Search This Blog

Showing posts with label C# numeric value in textbox. Show all posts
Showing posts with label C# numeric value in textbox. Show all posts

Wednesday, January 5, 2011

Allow only numeric value in textbox

To allow only numeric value in textbox, the KeyPress event of the text box can be handled to achive it. You will just need to add the following code.

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)  
{
        if (!char.IsNumber(e.KeyChar) & (Keys)e.KeyChar != Keys.Back)
        {
              e.Handled = 
true;
         }
}