How do i control the user input to a textbox that only accepts int ? C# please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sword117
    New Member
    • Jun 2010
    • 35

    #1

    How do i control the user input to a textbox that only accepts int ? C# please

    i already got this.
    Code:
     private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
            {
         int ascii = Convert.ToInt16(e.KeyChar);
                if ((ascii >= 48 && ascii <= 57) || (ascii == 8) || (ascii==32))
                {
    
                    e.Handled = false;
    
                }
    
                else
                {
    
                    e.Handled = true;
    
                }
    }
Working...