Solved

Is mouse over form

Posted on 1998-08-30
8
160 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

820 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