954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

"enter" event

hi,

can anyone tell me what's wrong with my code or show me a working code to add in to my program so that i can study and understand how the code actually works..

after i type in textbox, i want to be able to hit "enter" key instead of clicking on the button.. i do not mean that i want to disable clicking on the button.. i just want to let user be able to hit "enter" too.. my textBox is named textBox4, button is button3 and after the button is hit, it should open a tab page called tabPage6 under tabControl1...


private void button3_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==(char)13)
{
this.GetNextControl(textBox4,true).Focus();
tabControl1.Focus();
tabControl1.SelectedTab=tabPage6;
e.Handled=true;
}
}

thanks!

c#dummie
Light Poster
38 posts since Jul 2005
Reputation Points: 10
Solved Threads: 1
 

if you are typing in a textbox then the focus is laying on that textbox, so when hitting enter will occur on the event of the textbox not the button

Huntondoom
Light Poster
48 posts since Jul 2010
Reputation Points: 10
Solved Threads: 5
 

You can also use the AcceptButton property of the Form. This will however, capture the Enter key from any control on the Form. But, this generates the button's Click event, a mouse click or enter key can be handled in the same method.

nmaillet
Posting Whiz in Training
236 posts since Aug 2008
Reputation Points: 69
Solved Threads: 53
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You