Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

Is mouse over form

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
smithgr
Asked:
smithgr
  • 4
  • 3
1 Solution
 
DalinCommented:
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
 
smithgrAuthor Commented:
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
 
smithgrAuthor Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
kamallCommented:
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
 
DalinCommented:
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
 
smithgrAuthor Commented:
Thanks but Dalin hit it right on the head
Gary
0
 
smithgrAuthor Commented:
Thanks Dalin, that was exactly what I was looking for!

Gary
0
 
DalinCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now