A TextBox which Accepts only Integer in C#

Drag and drop a TextBox. Now, go to in property of the textbox and double click on the "KeyPress event".
 
 priavate void textbox_keypress(obj sender_event e)
 {
     if(e.keychar >= '0' && e.keychar <= '9')
     {
          e.handled = false;
     }
     else
     {
          e.handle = true;
     }
 }
 
Before doing this code, it is necessary for the keypress event to write this code:
 
 public form()
 {
     initializeComponent();
     textbox.text.keypress + = new keypressEventHandler(text.box_keypress);
 } 

Ebook Download
View all
Learn
View all