您可以将文本框的textlength与文本框的最大长度进行比较,如果它们匹配,则下一个
Private Sub TextBox1_TextChanged(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
If TextBox1.TextLength = TextBox1.MaxLength - 1 Then
TextBox2.Focus()
End If
End Sub
一旦输入最后一位数字,这将把焦点切换到textbox2 .
如果你想在按钮事件中使用它,那么就像上面一样,但没有 - 1
如果您希望始终保持文本相同,请执行以下操作:
Private Sub SubBttn_Click(sender As Object, e As EventArgs) Handles SubBttn.Click
If TextBox1.TextLength = TextBox1.MaxLength Then
TextBox2.Text = TextBox1.Text
TextBox2.Focus()
End If
End Sub
您将为每个文本框重复相同的操作,例如:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.TextLength = TextBox1.MaxLength Then
TextBox2.Text = TextBox1.Text
TextBox2.Focus()
End If
If TextBox2.TextLength = TextBox2.MaxLength Then
TextBox3.Text = TextBox2.Text
TextBox3.Focus()
End If
If TextBox3.TextLength = TextBox3.MaxLength Then
TextBox4.Text = TextBox3.Text
TextBox4.Focus()
End If
End Sub
希望这可以帮助!