lskuff
February 22nd, 2006, 12:45 PM
What's the easiest way to make a user only able to enter valid hexadecimal digits (0-9, a/A-f/F) into a textbox? I don't want any messageboxes to pop up I just want nothing to happen if the user enters an invalid character.
jhammer
February 22nd, 2006, 01:26 PM
Look into the KeyPress event of the TextBox, you can know the exact key that was pressed, and set the property e.Handled to be true (so the character will not be shown).
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if ("ABCDEF0123456789".IndexOf(e.KeyChar) == -1)
e.Handled = true;
}