Reputation: 576
In C#, i want to execute some method, when click event is triggered.
Not only single button click but, whole click event did this automatically.
For example, i have 3 buttons, and when i click these buttons, just execute one method.
In short, every buttons event executes the same method, when these buttons are triggered.
button1 event is triggered -> execute method0
button2 event is triggered -> execute method0
button3 event is triggered -> execute method0
Please help me. I have tons of buttons that has to execute the same method.
Upvotes: 0
Views: 201
Reputation: 4622
Just create a single method that you want to execute, then set your buttons' Click event to that:
void Method(object sender, EventArgs e){
// Do something
}
Then you can set the click event:
button1.Click += Method;
button2.Click += Method;
button3.Click += Method;
buttonN.Click += Method;
Hope it helps!
Upvotes: 7