PDA

Click to See Complete Forum and Search --> : Please help me with MouseMove Events


Valley Boy
Jan 2nd, 2000, 12:48 AM
I need help writing code, so that when I move the mouse cusor over a certain part of a picture words get displayed in a textbox. The co ordinates are 2040 & 2280.

Bob Baddeley
Jan 2nd, 2000, 02:55 AM
1. Start a new standard EXE project in Visual Basic; form1 is created by default.

2. Add a standard module to the project by clicking on project on the Visual Basic menu and select 'Add Module'. Module1 is opened up by default.

3. Type the following, making sure that the API call is on one line

Option Explicit

Type POINTAPI 'Declare types
x As Long
y As Long
End Type

Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long 'Declare API

4. Open up Form1 and add one timer. Set the interval property of the timer to 1. Open up the code window to form1 and type the following

Option Explicit
Dim z As POINTAPI 'Declare variable

Private Sub Timer1_Timer()
GetCursorPos z 'Get Co-ordinets
If z.x >2000 and z.x<3000 and z.y > 2200 and z.y < 2300 Then
Insert code here
Else
End if
End Sub

5. Run the program. Move the mouse around and watch the two labels on Form1

This is a modified version of the tip under mouse/keyboard in this site. It has been formatted to fit your program. FBI warning: Illegal copying or distribution is prohibited by law and subject to ... I can't remember it all. Hope it helps.

bob

MartinLiss
Jan 2nd, 2000, 02:56 AM
The first example should do it, but your coordinates point to just one pixel, and that is a very small target, so maybe you should consider simething like the second example.
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If X = 2040 And Y = 2280 Then
MsgBox "Hi"
End If

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

If X > 2020 And X < 2060 And Y > 2260 And Y < 2300 Then
MsgBox "Hi"
End If

End Sub



------------------
Marty

Bob Baddeley
Jan 2nd, 2000, 08:17 AM
Wow, did you see how close the times were on those two? We were both working on it at the same time. I think I like his better, especially the second one.