Solved

Is mouse over form

Posted on 1998-08-30
8
161 Views
Last Modified: 2010-04-30
Okay, I have the getcursorpos working and it shows the mouse units in (?) pixels?  However the left/top etc of the form are in some other notation, how can I determine if the mouse coordinates are actually over my form?  Thanks
0
Comment
Question by:smithgr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 9

Expert Comment

by:Dalin
ID: 1431984
smithgr,
Try this. let me know if you have questions.
Regards
Dalin

In the form's mouse_move event, add:

Dim MouseOver As Boolean
' See if the mouse is over
 MouseOver = (0 <= X) And (X <= Me.Width) And (0 <= Y) And (Y <= me.Height)

If MouseOver Then
         ' MouseOver is over your form
    End if
0
 
LVL 1

Author Comment

by:smithgr
ID: 1431985
This works if the mouse is over the form but not if the mouse is off the form...ie, I set - label1.caption = "over" if true and label1.caption = "not over" if false...???? I really need to know when the mouse leaves the form...
0
 
LVL 1

Author Comment

by:smithgr
ID: 1431986
Rejecting this to leave this open again? I'm confused as to how this works...scoring....I'll give the credit once I figure this out...thanks
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 7

Expert Comment

by:kamall
ID: 1431987
Just multiply the coordinates you get from the GetCursorPos (in pixels) by 15 to get the equivalent number in twips which is the one used in your form for the Top/Left/Height/Width properties.

Regards
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1431988
smithgr,
Do the following:
' In for form's general Declaration area, after "Option Explicit", add:

  Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
  Private Declare Function ReleaseCapture Lib "user32" () As Long

drop a text box to the form, name it text1

'In the MouseMove Event of the form, add"

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim MouseOver As Boolean
' See if the mouse is over
MouseOver = (0 <= X) And (X <= Me.Width) And (0 <= Y) And (Y <= Me.Height)

If MouseOver Then
   ' MouseOver is true
    Text1 = "Mouse is over the form"
    SetCapture Me.hWnd
    Else
    ' Mouse Left
          'Do something else
        Text1 = "Mouse is Not over the form"
 ReleaseCapture
 End If
End Sub


Regards
Dalin
0
 
LVL 1

Author Comment

by:smithgr
ID: 1431989
Thanks but Dalin hit it right on the head
Gary
0
 
LVL 1

Author Comment

by:smithgr
ID: 1431990
Thanks Dalin, that was exactly what I was looking for!

Gary
0
 
LVL 9

Accepted Solution

by:
Dalin earned 50 total points
ID: 1431991
smithgr,
I am glad it worked for you.
Regards.
kamall, How are you? How much left in your thesis?
Hope everything going OK for you.
Dalin
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question