Click here to Skip to main content
15,913,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void txtphon_KeyDown(object sender, KeyEventArgs e)
{
    if ((e.Key >= Key.D0 && e.Key <= Key.D9) || (e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9))
    {
        //Do nothing
    }
    else
    {
        e.Handled = true;
    }
}

this handles only numbers but i want that text box handle only characters
Posted

You need to modify the condition a little to check for alphabet
i.e.
C#
if (e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z)


However, this will work only if you are talking about english.

-Milind
 
Share this answer
 
C#
private void textbox1_KeyDown_1(object sender, KeyEventArgs e)
        {
            if (e.Key >= Key.A && e.Key <= Key.Z)
            {

            }
            else
            {
                e.Handled = true;
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900