C # is it possible to fire a button_click event with code?

I do not want to press a button. instead, I just want to run the click event code. how would i do that?

+5
source share
5 answers
button1_click(null, new EventArgs() );
+11
source

Option: use PerformClick().

Take a look here: How to invoke the "Click on event" button Programmatically .

The advantage here is that the behavior of the event will be exactly the same as the actual click of a button (like a direct call button1_click).

. , ! button1_click .

+9

Inside or outside Form, where is it located Button? The easiest way is to simply call the function:

Button1_Click(Button1, EventArgs.Empty);
+2
source

I sometimes do this by actually calling the event handler function what if I really implemented it.
Literally call it this:

button1_Click(this, new EventArgs());
+1
source

All Articles