' 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
|