Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base

Post new topic   Reply to topic
Center the Mouse Pointer on a Control when it gets Focus
View previous topic :: View next topic  
Author Message
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Oct 8th, 2003 04:06 AM    Post subject: Center the Mouse Pointer on a Control when it gets Focus Reply with quote

Code:
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Dim Rec As RECT

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Function CenterMouse(obj As Object)
    'Get Left, Right, Top and Bottom of Object
    GetWindowRect obj.hwnd, Rec
    'Set Cursor position on center of Object
    SetCursorPos Rec.Left + obj.Width / 2, Rec.Top + obj.Height / 2
End Function

Private Sub Command2_GotFocus()
Call CenterMouse(Command2)
End Sub

Private Sub Command1_GotFocus()
Call CenterMouse(Command1)
End Sub

Private Sub Form_Load()
ScaleMode = 3 'It must be set to pixels
MsgBox "Use the ""Tab"" key to notice the effect better"
End Sub
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic