This has me very confused. I have an array of textboxes created at run time. I want to navigate through them using the arrow keys. The code below successfully creates the boxes and both the left and right arrow keys work fine. However, the up and down arrow keys WON'T work. If I substitute another key, such as Shift or Alt, the keys move the cursor up and down just fine. Moreover, if I put a STOP command in the routine, to see if the up and down arrows are detected the program stops. Why? Can anyone shed light on this, please.
This creates the textboxes:
Public B() As TextBox
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Create the textboxes, n an array, that constitutes the board
Static V, H
ReDim B(81)
V = 5
H = -41
For r = 1 To 81
H = H + 47
If H > 400 Then
H = 6
V = V + 46
End If
B(r) = New TextBox
With B(r)
.Font = New System.Drawing.Font("Microsoft Sans Serif", 21.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
.ForeColor = System.Drawing.Color.Blue
.BackColor = Color.Snow
.Location = New System.Drawing.Point(H, V)
.Multiline = True
.Name = ""
.Size = New System.Drawing.Size(42, 40)
.TabIndex = 0
.Tag = r
'.Text = LTrim(Str(r))
.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
AddHandler .KeyDown, AddressOf Arrows_Code
End With
Me.Controls.Add(B(r))
Next
End SubThis is the arrow scroll code:
Sub Arrows_Code(sender As System.Object, e As System.Windows.Forms.KeyEventArgs)
Static po
po = sender.tag
' Move Back
'TextBox1.Text = e.KeyCode
If e.KeyCode = 37 Then
po = po - 1
If po = 0 Then po = 81
B(po).Focus()
End If
' Move Forward
If e.KeyCode = 39 Then
po = po + 1
If po = 82 Then po = 1
B(po).Focus()
End If
' Move down
If e.KeyCode = 40 Then ' Works for other keys, like shift (keycode = 18), but not for down arrow!
po = po + 9
If po > 81 Then po = po - 82
If po = 0 Then po = 9
B(po).Focus()
End If
'Move up
If e.KeyCode = 38 Then ' Work for ALT key, Keycode = 16, but not for up arrow!
po = po - 9
If po < 0 Then po = po + 82
If po = 0 Then po = 73
B(po).Focus()
End If
End Sub