Results 1 to 5 of 5

Thread: mouse position

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539

    Unhappy

    again.. i got 2 forms hehe

    when right clicking one
    second one appears
    how do i make it so that when second one apears
    it will appear at the place where mouse was clicked?
    (in other words, how do i capture mouse positions..)

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    Private Sub Form_Load()
        Dim mypt As POINTAPI
        GetCursorPos mypt
        MsgBox "Cursor at: " & mypt.x & ", " & mypt.y
    End Sub
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539

    Unhappy hmm

    Code:
    Private Sub Form_Mouseup(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = 2 Then
        Form2.Show
        Dim MousePosition As POINTAPI
        GetCursorPos MousePosition
        Form2.Move Form1.Left + MousePosition.x, Form1.Top + MousePosition.y
    
    End If
    End Sub
    i tried that.. but that doesnt display form2 where the mouse was clicked
    any times? (first time playing around with move and cursor stuff)

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Try this:
    Code:
    Private Sub Form_Mouseup(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = 2 Then
        Form2.Show
        Dim MousePosition As POINTAPI
        GetCursorPos MousePosition
        Form2.Move Form1.Left + (MousePosition.x * Screen.TwipsPerPixelX), Form1.Top + (MousePosition.y * Screen.TwipsPerPixelY)
    End If
    End Sub
    The windows API returns all positions/sizes/etc in pixels. VB works in Twips.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539

    Talking here we go..

    thanks parksie
    just had to modify it a little bit
    Code:
    If Button = 2 Then
        Form2.Show
        Dim MousePosition As POINTAPI
        GetCursorPos MousePosition
        Form2.Move (MousePosition.x * Screen.TwipsPerPixelX), (MousePosition.y * Screen.TwipsPerPixelY)
        EnableTrap Form2
    End If
    greatly appreciated..

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