movecursortocontrol

 

Move Cursor To The Control That Has Focus


Move Cursor To The Control That Has Focus

'Add a module to your project (In the menu choose Project -> Add Module,
Then click Open)
'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
same
'thing with other controls.
'Insert the following code to your module:

Declare Sub SetCursorPos Lib "User32" (ByVal X As Integer, ByVal Y As
Integer)

'Insert the following code to your form:

Private Sub Command1_GotFocus()
'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