How do I make a textbox that only accepts numbers?

Total Post:108

Points:756
C# 
C#
 1288  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. 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-03-2018 05:51:05 AM

Answer