Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitlePosition a form under the mouse
Keywordsposition, form, mouse
CategoriesTips and Tricks, API
 
Use GetCursorPos and ScreenToClient to see where the mouse is in form coordinates. Then move the form to the appropriate position.
 
' Center the form at the mouse.
Private Sub PositionFormOverMouse(ByVal frm As Form, ByVal _
    target_x As Single, ByVal target_y As Single)
    ' Get the current mouse position.
    GetCursorPos pt

    ' Convert into form client area coordinates.
    ScreenToClient frm.hwnd, pt

    ' Convert to twips.
    mouse_x = frm.ScaleX(pt.x, vbPixels, vbTwips)
    mouse_y = frm.ScaleY(pt.y, vbPixels, vbTwips)

    ' Center the form at this position.
    frm.Left = frm.Left + mouse_x - target_x
    frm.Top = frm.Top + mouse_y - target_y
End Sub

Private Sub Form_Click()
    PositionFormOverMouse Me, ScaleWidth / 2, ScaleHeight / _
        2
End Sub
 
Formatted by Neil Crosby
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated