Home > DeveloperSection > Forums > How do I make a textbox that only accepts numbers?
john rob

Total Post:108

Points:756
Posted on    November-13-2013 7:29 AM

 C# C# 
Ratings:


 1 Reply(s)
 830  View(s)
Rate this:
I have a textbox in a simple windows form application and i want the textbox only accept the number. How to make a textbox accept only numbers? 


ezra heywood
ezra heywood

Total Post:145

Points:1019
Posted on    November-13-2013 7:50 AM

Hi John,

You can try this:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

    {

        e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);

    }

Hope this will solve your problem.


Modified On Apr-04-2016 11:28:56 PM

Don't want to miss updates? Please click the below button!

Follow MindStick