Results 1 to 4 of 4

Thread: Please help me with MouseMove Events

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Location
    cardiff
    Posts
    17

    Post

    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.

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305

    Post

    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

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    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.
    Code:
    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
    Code:
    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

  4. #4
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305

    Post

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width