이 소스도 결국엔 SetCursorPos API 함수 이용한다. 각 컨트롤의 GotFocus 이벤트에 focus() 함수를 추가해주면 된다.



Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

Private Sub focus()
    If Me.BorderStyle = 0 Then
        x& = Me.ActiveControl.Left Screen.TwipsPerPixelX + ((Me.ActiveControl.Width / 2) / Screen.TwipsPerPixelX) + (Me.Left / Screen.TwipsPerPixelX)
        y& = Me.ActiveControl.Top Screen.TwipsPerPixelY + ((Me.ActiveControl.Height / 2) / Screen.TwipsPerPixelY) + (Me.Top / Screen.TwipsPerPixelY)
    Else
        x& = Me.ActiveControl.Left Screen.TwipsPerPixelX + ((Me.ActiveControl.Width / 2 + 60) / Screen.TwipsPerPixelX) + (Me.Left / Screen.TwipsPerPixelX)
    ' "+ 60" is for the border"
        y& = Me.ActiveControl.Top Screen.TwipsPerPixelY + ((Me.ActiveControl.Height / 2 + 360) / Screen.TwipsPerPixelY) + (Me.Top / Screen.TwipsPerPixelY)
    ' "+ 360 " is for the border and the tittle bar"
    End If
    a& = SetCursorPos(x&, y&)
End Sub

Private Sub Text1_GotFocus()
    Call focus
End Sub






Source Page : http://www.mentalis.org/tips/tip062.shtml