Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Is mouse over form

Posted on 1998-08-30
8
Medium Priority
?
163 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Suggested Courses

719 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