Results 1 to 7 of 7

Thread: Position Form Using Mouse Coordinates

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Location
    Barbados, Caribbean
    Posts
    7

    Question Position Form Using Mouse Coordinates

    hi guyz,
    when the user clicks a label on a form, i wish to load a new form and position the new form such that the new form's top-left hand corner is at the mouse's coordinates.

    i know how to use GetCursorPos to get the mouse coordinates but after that i'm lost.

    thanks for your help guyz...
    Rommel the iCeMAn,
    Computer Programmer,
    Barbados, Caribbean.

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    VB Code:
    1. Form2.Left = returnedMousePositionX
    2. Form2.Top = returnedMousePositionY

    API usually returns in pixels, VB defaults to twips...

    So you may have to:
    VB Code:
    1. Form2.Left = Screen.TwipsPerPixelX * returnedMousePositionX
    2. Form2.Top = Screen.TwipsPerPIxelY * returnedMousePositionY

    where returnedMousePositionX , Y are the mouse coordinates...

  3. #3
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    This will explain it a little more clearly than nemaroller.
    VB Code:
    1. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    2.  
    3. Private Type POINTAPI
    4.         x As Long
    5.         y As Long
    6. End Type
    7.  
    8. Private Sub Command1_Click()
    9.  Dim NewFrm1 As New Form1 '<- copy the current form
    10.  Dim CursorPos As POINTAPI '<- the form pos will be here
    11.  
    12.  GetCursorPos CursorPos '<- Sets CursorPos
    13.  
    14.  CursorPos.y = CursorPos.y * Screen.TwipsPerPixelY
    15.  CursorPos.x = CursorPos.x * Screen.TwipsPerPixelX
    16.  '^         converts pixels to twips             ^
    17.  
    18.  NewFrm1.Top = CursorPos.y '<- Sets NewFrm1's top pos
    19.  NewFrm1.Left = CursorPos.x '<- Sets NewFrm1's left pos
    20.  
    21.  NewFrm1.Show '<- Displays your new form!
    22. End Sub
    Luke

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Christ Macai, how'd you know what I was going to post?

  5. #5
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    Originally posted by nemaroller
    Christ Macai, how'd you know what I was going to post?
    It becomes common knowledge amongst VBers... im just faster
    than you.
    Luke

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Location
    Barbados, Caribbean
    Posts
    7
    hehehehe ...
    thanks guyz ... i do some fairly advanced database programming, sometimes i even crossover from VB to Linux DBs .. yet the small stuff like this often eludes me!



    thanks again...
    Rommel the iCeMAn,
    Computer Programmer,
    Barbados, Caribbean.

  7. #7
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    Im good at alot of stuff. But im weird with DBs! I wrote my own
    DB format, but i just cant get the hang on Access or SQL!!
    Luke

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