Search This Blog

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;
         }
}
      

No comments:

Post a Comment