How to Move the Cursor to the Control that has focus
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 'System & API - How to Move the Cursor to the Control that has focus Option Explicit 'Add 2 CommandButtons to your form. Run the program and move between buttons with TAB key. 'We show this example on CommandButtons, but You can do the samething with other controls. Declare Sub SetCursorPos Lib "User32" (ByVal X As Integer, ByVal Y As Integer) Private Sub Command1_GotFocus() Dim X%, Y% 'Replace All 'Command1' With the name of the control you want to move the cursor to him. X% = (Form1.Left + Command1.Left + Command1.Width / 2 + 60) / Screen.TwipsPerPixelX Y% = (Form1.Top + Command1.Top + Command1.Height / 2 + 360) / Screen.TwipsPerPixelY SetCursorPos X%, Y% End Sub |