Resolved Textbox format backspace

sigster

Member
Joined
Feb 7, 2010
Messages
12
Programming Experience
Beginner
Hi

How can I make this work in KeyPress when I use backspace I can not remove minus sign and fyrst 2 number = 01-

VB.NET:
       If Not (Char.IsDigit(e.KeyChar) Or e.KeyChar = "-") And Not Char.IsControl(e.KeyChar) Then
            e.Handled = True
        End If


        If Txt_number.TextLength = 2 Then
            Txt_number.Text = Txt_number.Text + "-"
            Txt_number.SelectionStart = Len(Txt_number.Text)
        End If

Regards
Sigster
 
It work like this

VB.NET:
    If Not (Char.IsDigit(e.KeyChar) Or e.KeyChar = "-") And Not Char.IsControl(e.KeyChar) Then
            e.Handled = True
        End If

        If Char.IsControl(e.KeyChar) Then
        
        Else
        If Txt_number.TextLength = 2 Then
            Txt_number.Text = Txt_number.Text + "-"
            Txt_number.SelectionStart = Len(Txt_number.Text)
        End If       
          End If
 
Back
Top