Re: [RESOLVED]keypress in C#
The "proper" way to do this would be to handle the KeyPress event to prevent invalid characters being typed in and then override the WndProc method to intercept WM_PASTE (I think) messages to prevent invalid data being pasted in. What you've done will do a job but it's a bit of a hack, plus it could get rather annoying to the user if they type 10 valid characters and then accidentally type an invalid one and you wipe out the entire text. It also means that the user can't clear the TextBox and start typing because your code will stick a zero in there.
Re: [RESOLVED]keypress in C#
Sir, I want to adapt your code but. I don't know how to use that. I get some error.
Code:
private void keypress_charOnly(object sender, KeyPressEventArgs e)
{
char keyChar = e.KeyChar;
e.Handled == char.IsDigit(keyChar);
}
Is this the proper way in doing that? Sorry again.. I am new in C#.. :(