Manually trigger an event.

  • Thread starter Thread starter .pd.
  • Start date Start date
P

.pd.

Hi,

I've got a textbox and button and when the user presses Enter in the
textbox, I want the button's click event to fire.

I've got as far as using the KeyPress event to check for the Enter key but
how do I get the button's click event to fire without actually clicking the
button?

Cheers,
..pd.
 
I've got a textbox and button and when the user presses Enter in the
textbox, I want the button's click event to fire.

I've got as far as using the KeyPress event to check for the Enter key but
how do I get the button's click event to fire without actually clicking the
button?

First, create event handler for your button. It will look like
MyButton_Click(object sender, System.EventArgs e)
Next, when pressing Enter key was handler call the event hander
MyButton_Click(MyButton,EventArgs.Empty)
 
Hi pd, max,

They made it even easier for us. :-)

MyButton.PerformClick

Regards,
Fergus
 
Back
Top