I have a form with 30 textboxes which I want to function as if they are only 1 textbox.
I have them separated for user friendly appearance purposes. Each box is paired with a checkbox so that letters appear exactly above and center to the check box no matter what size/case the rest of the letters are.
When a letter is entered in txtBox1, txtBox2 gets focus and if a character is deleted from txtBox2 focus goes to txtBox1.
Private Sub inputTxtBox01_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles inputTxtBox01.TextChanged
If inputTxtBox01.Text <> "" And inputTxtBox02.Enabled = True Then
inputTxtBox02.Focus()
ElseIf inputTxtBox01.Text = "" Then
inputTxtBox01.Focus()
End If
End Sub
coded in each box to function the same way
I was trying to handle a box which is empty but the user presses backspace key to delete previous character. The code above wont work because there is no text in the current box yet so I need to detect the key and this is where I'm having trouble...
Forgive me if this is horrible because I really did not know where to begin with this. I have never tried handling keydown/keypress etc events before.
Also, I was tired of typing out all my code 30x so I was trying to make code that would apply to all 30 text boxes in one code block.
Private Sub inputTxtBox01_TextChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles inputTxtBox01.KeyDown, inputTxtBox02.KeyDown, inputTxtBox03.KeyDown, inputTxtBox04.KeyDown, inputTxtBox05.KeyDown, inputTxtBox06.KeyDown, _
inputTxtBox07.KeyDown, inputTxtBox08.KeyDown, inputTxtBox09.KeyDown, inputTxtBox10.KeyDown, inputTxtBox11.KeyDown, inputTxtBox12.KeyDown, _
inputTxtBox13.KeyDown, inputTxtBox14.KeyDown, inputTxtBox15.KeyDown, inputTxtBox16.KeyDown, inputTxtBox17.KeyDown, inputTxtBox18.KeyDown, _
inputTxtBox19.KeyDown, inputTxtBox20.KeyDown, inputTxtBox21.KeyDown, inputTxtBox22.KeyDown, inputTxtBox23.KeyDown, inputTxtBox24.KeyDown, _
inputTxtBox25.KeyDown, inputTxtBox26.KeyDown, inputTxtBox27.KeyDown, inputTxtBox28.KeyDown, inputTxtBox29.KeyDown, inputTxtBox30.KeyDown
Dim o As Object
If TypeOf sender Is Button Then
Dim btn As Button = CType(sender, Button)
If e.KeyCode = Keys.Back Then
If btn.Name.Substring(11, 2) <> "01" Then
For Each o In Me.Controls
If TypeOf o Is Button And o.name.contains("inputTxtBox" + Val(btn.Name.Substring(11, 2) - 1).ToString) Then
o.focus()
o.clear()
End If
Next
End If
End If
End If
End Sub
Part of my problem is that this simply does nothing... no errors. It just does not work so, I think I may be going about this entirely wrong :(