Use "ENTER" key for button
-
20 สิงหาคม 2555 17:22
Hi,
I have a a form which has one button. I would like to use the "ENTER" key instead of clicking on the button to log in.
Here's the button code:
private void button1_Click(object sender, EventArgs e) { if (username.Text == "test" && password.Text == "test") { this.Hide(); Form1 fr = new Form1(); fr.Show(); } else { MessageBox.Show("Incorrect Name or Password"); } }
ตอบทั้งหมด
-
20 สิงหาคม 2555 17:29
Hello rushelp,
Define button1 as an "Accept Button" of your form.
Go into your Form's properties and assign button1 as the AcceptButton.
The button's click event will be triggered when the user presses Enter.
- ทำเครื่องหมายเป็นคำตอบโดย rushelp 20 สิงหาคม 2555 18:04
-
20 สิงหาคม 2555 17:29ผู้ดูแลYou can do this by setting the button as the Form's AcceptButton. See: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.acceptbutton.aspx
Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful". -
20 สิงหาคม 2555 18:04
Steve,
Thank you.
-
22 สิงหาคม 2555 3:29Go To Proprties of button and make the dialog result and make it OK and go to proprties form in misc and make button 1 as Accept Button please Mark as Answer and vote as helpful
- แก้ไขโดย Ahmed youness 22 สิงหาคม 2555 3:31