Patrick_ Posted September 22, 2004 Share Posted September 22, 2004 Hey all. I would like to know the code so that, if one presses the Enter Key in Textbox1.text, it would call to press the button I would like to press. Anyone know it? Link to comment Share on other sites More sharing options...
0 umerh Posted September 22, 2004 Share Posted September 22, 2004 its very simple... i do it this way in C#: i dont have have the VS.NET on this machine so the code might not be the exact: protected TextBox1_KeyPress(Object sender, KeyCharArgs e) if (e.KeyChar == (char)Keys.Enter) { Button1_Click(sender, e); } anybody if i am not wrong please correct me.... Umer Link to comment Share on other sites More sharing options...
0 Winston Posted September 22, 2004 Share Posted September 22, 2004 hmmmm why do you need to cast it? :s i think this should work too If e.KeyValue = Keys.Enter Then Me.Button1_Click(sender, e) End If Link to comment Share on other sites More sharing options...
0 umerh Posted September 23, 2004 Share Posted September 23, 2004 well try my above code in C# it wont work without casting... Link to comment Share on other sites More sharing options...
0 DrZoidberg Posted September 23, 2004 Share Posted September 23, 2004 Why not just set the "AcceptButton" property of the parent form to the button? Much easier than messing around with KeyPress events. Link to comment Share on other sites More sharing options...
Question
Patrick_
Hey all. I would like to know the code so that, if one presses the Enter Key in Textbox1.text, it would call to press the button I would like to press. Anyone know it?
Link to comment
Share on other sites
4 answers to this question
Recommended Posts