HOW DO I MAKE A TEXTBOX THAT ONLY ACCEPTS NUMBERS?

john rob

Total Post:108

Points:756
Posted by  john rob
C# 
C#
 1060  View(s)
Ratings:
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? 
  1. ezra heywood

    Post:145

    Points:1019
    Re: How do I make a textbox that only accepts numbers?

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!