Thursday, November 18, 2010

Programming code for using on the s, d, S, D or backspace

NOTE: to see if you do this right and you are successful, you should be able to put anything in the textbox except s, S, d, D or the backspace key
'First of all you need to go to the code and choose the name of the text box. The name should be something like: txtType and choose KEYPRESS
It will generate this code:
Private Sub txtType_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtType.KeyPress

'This is the code you put in the Keypress sub
' allows the text box to accept only the letters
' S, s, D, and d and the Backspace key for editing.
If e.KeyChar <> "S" AndAlso e.KeyChar <> "s" AndAlso e.KeyChar <> "D" AndAlso e.KeyChar <> "d" AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If

11 comments: