How to raise by code the click event of a button in C#

  • Thread starter Thread starter polocar
  • Start date Start date
P

polocar

Hi all,
I'm writing a C# program, and I was wondering: is there a way to raise
by code the click event of a Button control, as if it was the user to
have clicked on it?

Thank you very much
 
Why wouldn't you just execute the method that Button.Click executes on your
form instead?
 
PerformClick();

But note that it is often (not always) better to simply call the backer
directly.

Exceptions would include scenarios where *you don't know* what the backer
is, or where you want it to run any code that the Button would (perhaps you
have overridden the OnClick implementation).

Marc
 

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