Trigger control's event programmatically

steavy picture steavy · Aug 29, 2012 · Viewed 91.8k times · Source

Assume that I have a WinFoms project. There is just one button (e.g. button1).

The question is: is it possible to trigger the ButtonClicked event via code without really clicking it?

Answer

itsme86 picture itsme86 · Aug 29, 2012

Button controls have a PerformClick() method that you can call.

button1.PerformClick();