Insert Only Numeric Value In TextBox(Windows Application)


This code demonstrates how to Insert Only Numeric Value In TextBox(Windows Application)

Insert Only Numeric Value In TextBox(Windows Application)


private bool nonnumberenter = false;
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
nonnumberenter = false;
if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
{
if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
{
if (e.KeyCode != Keys.Back)
{
nonnumberenter = true;
}
}
}
if (Control.ModifierKeys == Keys.Shift)
{
nonnumberenter = true;
}
}


Comments

Author: PHANI HARSHITHA MADALA09 Feb 2010 Member Level: Gold   Points : 1

Hi Mr.hardik,

Very usefull info..

Thanks for sharing with all of us.


regards,

harshitha



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: