Public Class Form1
Private LastTextBox As TextBox = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim tb As TextBox
Dim ctls() As Control
For i As Integer = 0 To 71
ctls = Me.Controls.Find("TextBox" & i, True)
If ctls.Length > 0 AndAlso TypeOf ctls(0) Is TextBox Then
tb = CType(ctls(0), TextBox)
AddHandler tb.GotFocus, AddressOf tb_GotFocus
End If
Next
End Sub
Private Sub tb_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
Dim tb As TextBox = CType(sender, TextBox)
LastTextBox = tb
End Sub
Private Sub btnRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRight.Click
If Not IsNothing(LastTextBox) Then
Dim i As Integer
Dim strInt As String = LastTextBox.Name.Remove(0, "TextBox".Length)
If Integer.TryParse(strInt, i) Then
If ((i + 1) Mod 9) <> 0 Then
i = i + 1
Dim ctls() As Control = Me.Controls.Find("TextBox" & i, True)
If ctls.Length > 0 AndAlso TypeOf ctls(0) Is TextBox Then
Dim tb As TextBox = CType(ctls(0), TextBox)
tb.Focus()
End If
Else
LastTextBox.Focus()
End If
End If
End If
End Sub
Private Sub btnLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeft.Click
If Not IsNothing(LastTextBox) Then
Dim i As Integer
Dim strInt As String = LastTextBox.Name.Remove(0, "TextBox".Length)
If Integer.TryParse(strInt, i) Then
If (i Mod 9) <> 0 Then
i = i - 1
Dim ctls() As Control = Me.Controls.Find("TextBox" & i, True)
If ctls.Length > 0 AndAlso TypeOf ctls(0) Is TextBox Then
Dim tb As TextBox = CType(ctls(0), TextBox)
tb.Focus()
End If
Else
LastTextBox.Focus()
End If
End If
End If
End Sub
Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUp.Click
If Not IsNothing(LastTextBox) Then
Dim i As Integer
Dim strInt As String = LastTextBox.Name.Remove(0, "TextBox".Length)
If Integer.TryParse(strInt, i) Then
If i > 8 Then
i = i - 9
Dim ctls() As Control = Me.Controls.Find("TextBox" & i, True)
If ctls.Length > 0 AndAlso TypeOf ctls(0) Is TextBox Then
Dim tb As TextBox = CType(ctls(0), TextBox)
tb.Focus()
End If
Else
LastTextBox.Focus()
End If
End If
End If
End Sub
Private Sub btnDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDown.Click
If Not IsNothing(LastTextBox) Then
Dim i As Integer
Dim strInt As String = LastTextBox.Name.Remove(0, "TextBox".Length)
If Integer.TryParse(strInt, i) Then
If i < 63 Then
i = i + 9
Dim ctls() As Control = Me.Controls.Find("TextBox" & i, True)
If ctls.Length > 0 AndAlso TypeOf ctls(0) Is TextBox Then
Dim tb As TextBox = CType(ctls(0), TextBox)
tb.Focus()
End If
Else
LastTextBox.Focus()
End If
End If
End If
End Sub
End Class
|