Question

Can anyone tell me how to raise click event of button control (or for that matter for any event).

Platform: .net 2.0/3.0/3.5 Language: c# Domain: Windows Application, WinForms, etc.

Was it helpful?

Solution

You can use the Button.PerformClick method.

OTHER TIPS

Maybe the solution is much more simple:

Maybe you don't really want your code "to click the button".
Do you just want to run the code which is behind the button from another place in the form?

If yes, put the code into a separate method (like "DoActionXXX") and call the method from the button and from everywhere else where you need it.

You can also look into Windows Accessibility or some UI automation framework that allows you to programmatically cause UI controls to respond to user gestures. If a control does not offer a way for its events to be programmatically triggered like PerformClick, you can derive from that control and expose a public method like PerformnXXX that when called internally invokes the event handlers subscribed to a particular event.

button click and to new my manually window ex.. dital.cs open the may window

I dont think sending click events is the best way from a design point of you just make your event handler call another function. That way you always have access to that function.

so ..

void myEventHandler(ObjectwhoSentTheMessage O, Event e) {

MyOtherFunction();

//consume the event after if you wish etc

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top