Activate screen when hitting enter C# -


i have login screen , want activate when press enter in password textbox. problem though works, when close form app acts enter still pressed , form opens in endless loop.

here code:

  private void textbox2_textchanged(object sender, eventargs e)         {             textbox2.keydown += new keyeventhandler(textbox2_keydown);          }   public void textbox2_keydown(object sender, keyeventargs e)         {             if (user == username[1] && pass == passwords[1])                 {                     messagebox.show("login successfull", "welcome, hr");                     updatedbform newemployee = new updatedbform();                     this.hide();                     newemployee.showdialog();                       return;                  } } 

how tdo solve problem? thanks.

you assigning keydown-eventhandler everytime text changes:

private void textbox2_textchanged(object sender, eventargs e) {    textbox2.keydown += new keyeventhandler(textbox2_keydown); // evil! } 

this means, more input data textbox, more eventhandler assigned , when hit enter called many times. assign eventhandler once, i.e. in constructor , should work.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -