In the code below, only numbers, letters, backspace, and space are allowed.
I turned on VB.net because there was a complicated treatment that I had to deal with.
FROM#
private void textBoxSample_KeyPress(object sender, KeyPressEventArgs e) { e.Handled = e.KeyChar != (char)Keys.Back && !char.IsSeparator(e.KeyChar) && !char.IsLetter(e.KeyChar) && !char.IsDigit(e.KeyChar); }
Vb.net
Private Sub textBoxSample_KeyPress(sender As Object, e As KeyPressEventArgs) Handles textBoxSample.KeyPress e.Handled = e.KeyChar <> ChrW(Keys.Back) And Not Char.IsSeparator(e.KeyChar) And Not Char.IsLetter(e.KeyChar) And Not Char.IsDigit(e.KeyChar) End Sub
CrazyPaste
source share