Wednesday, December 5, 2012

How to make a Textbox to accept only digit in c#.net

 


 In the Keypress Event of a textBox just write the following Code

then it will get only number and no letter

   private void txtSalary_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            e.Handled = !(char.IsNumber(e.KeyChar) || e.KeyChar == '.' || e.KeyChar == (char)Keys.Back);
        }

No comments:

Post a Comment