i dont want to click the button. instead, i just want to run the click event code. how would i do this?
button1_click(null, new EventArgs() );
Option: use PerformClick()
.
Take a look here: How to: Call a Button's Click Event Programmatically.
The advantage here is that the event behavior will be exactly the same as a real button click (as oposed of calling button1_click
directly).
But none of this options is the best IMHO. If you need to call the event handler code, you need a new method! Just refactor the old button1_click
into a new, standard method and call it from wherever you want.
From inside or outside the Form
where the Button
is? Simplest thing is to just call the function:
Button1_Click(Button1, EventArgs.Empty);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With