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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top