Solved

Is mouse over form

Posted on 1998-08-30
8
156 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
  • 4
  • 3
8 Comments
 
LVL 9

Expert Comment

by:Dalin
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 7

Expert Comment

by:kamall
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 9

Expert Comment

by:Dalin
Comment Utility
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
Comment Utility
Thanks but Dalin hit it right on the head
Gary
0
 
LVL 1

Author Comment

by:smithgr
Comment Utility
Thanks Dalin, that was exactly what I was looking for!

Gary
0
 
LVL 9

Accepted Solution

by:
Dalin earned 50 total points
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now