如果KeyCode =,则关注下一个文本框。(DOT)

时间:2013-11-23 11:01:29

标签: vb.net

我有4个文本框,用于存储IP地址。我想通过输入。(DOT)字符来自动选择文本框;我希望在输入后立即删除此字符。我已经能够获得自动选择功能,但不能获得字符删除部分。这是我的代码:

   If e.KeyCode = Keys.OemPeriod Then

       TextBox2.Focus()
   End If

1 个答案:

答案 0 :(得分:1)

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
       If Asc(e.KeyChar) = 46 Then 'It does not matter how you select the character
            TextBox2.Focus()
            e.Handled = True 'To avoid the character to be written (i.e., delete the DOT)
        End If
    End Sub
    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
       If Asc(e.KeyChar) = 46 Then
            TextBox3.Focus()
            e.Handled = True
        End If
    End Sub
    Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
        If Asc(e.KeyChar) = 46 Then
            TextBox4.Focus()
            e.Handled = True 
        End If
    End Sub