c# - how enter in TextBox only digits from interval -


i try make form (c#, winforms) small program reminder. during have problem - whant make filter textbox user must enter start time event. result got next - on keypress event add code, allow enter digits, want user can enter digits diapasone.

code:

  private void startimetextbox_keypress(object sender, keypresseventargs e)     {         if ((e.keychar >= '0') && (e.keychar <= '9'))         {             return;         }         if (char.iscontrol(e.keychar))         {             if (e.keychar == (char) (keys.enter))                 starttimemmtextbox.focus();         }         e.handled = true;      } 

can using event or no?

try this:-

private void textbox1_keypress(object sender, keypresseventargs e)     {         e.handled = !char.isdigit(e.keychar) && !char.iscontrol(e.keychar);     } 

note:- can use textbox's maxlength property restrict user enter 2 digits. display message user can use textchanged event of textbox.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -