Link to home
Start Free TrialLog in
Avatar of lapucca
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(object 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. '@', '.', ',', '!','*' }
        }
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial