lapucca
asked on
How can I capture and prevent user from enter special charaters like *, @, and comma in KeyDown event?
What I have below is not working currently. It doesn't capture the '*' char. Also, how can I capture comma(,) and period(.)? Thank you.
private void txtContextName_KeyDown(obj ect sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Decimal || e.KeyCode == (Keys.Shift & Keys.D8) ||
e.KeyCode == (Keys.Shift & Keys.D1))
e.Handled = true;
//e.KeyCode == Keys. '@', '.', ',', '!','*' }
}
private void txtContextName_KeyDown(obj
{
if (e.KeyCode == Keys.Decimal || e.KeyCode == (Keys.Shift & Keys.D8) ||
e.KeyCode == (Keys.Shift & Keys.D1))
e.Handled = true;
//e.KeyCode == Keys. '@', '.', ',', '!','*' }
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.