Dear Experts,
I need a text box for entering only for 0 to 9,.,Delete key ,Backspace key and Enter key except this i want nothing to do for this i am coding like as given below

Private Sub TxtAmendment_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TxtAmendment.KeyDown

If (e.KeyCode >= 48 And e.KeyCode <= 57) Or e.KeyCode = 190 Or e.KeyCode = 8 Or e.KeyCode = 46 Then

Else
' I WANT TO RETURN 13 E.KEYCODE BUT UNABLE TO ASSIGN
e.KeyCode=13 'NOW ALLOWED

End If

End Sub


so suggest me how to return 13 or Enter Kay to e.keycode

Best Regards,
Pardeep

Recommended Answers

All 3 Replies

>> I need a text box for entering only for 0 to 9,.,Delete key ,Backspace key and Enter key

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Or Asc(e.KeyChar) = 13 Then
            e.Handled = True
        End If
        If Asc(e.KeyChar) = 8 Then
            e.Handled = False
        End If
    End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
            
            e.Handled = False
        End If
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.