I want to test some forms. Is there a way to simulate the press of an Ok (or Cancel) button so that the button is pressed and fires the event handlers that are associated with it?
The cleanest approach is to call the Click method of the button. This is better than the alternatives for these reasons:
Click
replicates what actually happens when the user clicks. It is what happens when the user presses the button. It deals with any actions that are associated with the button, for example. It sets the forms ModalResult property. And so on.btn_ok.click
or btn_okClick(sender);
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