You can call the event handler by calling something like
this.button1_Click(this.button1, null); from the textbox Keypress
eventhandler if the KeyChar value of the KeyPressEventArgs e is equal to
(char)13. However you might want to consider not placing the code to
be executed in the event handler itself but instead in a private method
and call that method from both the button Click and textbox Keypress
events. This concept can be extended by using the Command design pattern
which I have found leads to much cleaner code in winform applications.
For more information about the Command design pattern see:
http://www.dofactory.com/Patterns/PatternCommand.aspx
Regards,
Olle
Dundealing wrote:
I have a single button on my form, and when I press the Enter key while a
TextBox has focus I want the Button.Click event to fire.
Is there a simple way to do this ?