Erstellen Sie zwei Commandbuttons auf einem Formular. Mit der folgenden Funktion "SetCurs" wird automatisch beim Ereignis Form_Activate der Cursor auf die Mitte des Commandbuttons gesetzt.
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
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub SetCurs(ctl As Control)
Dim hWnd As Long
Dim tRect As RECT
hWnd = ctl.hWnd
GetWindowRect hWnd, tRect
SetCursorPos tRect.Left + ((tRect.Right - tRect.Left) / 2), tRect.Top + ((tRect.Bottom - tRect.Top) / 2)
End Sub
Private Sub Form_Activate()
SetCurs Command1
End Sub