So do you mean that you want to use a common event handler for those three buttons? If that's true and you use Forms, you can wire the click event to the same handler. So something like:
this.btnOk.Click += new EventHandler(CommonEventHanldlerForClick);
this.btnCancel.Click += new EventHandler(CommonEventHanldlerForClick);
this.btnModify.Click += new EventHandler(CommonEventHanldlerForClick);
void CommonEventHanldlerForClick(object sender, EventArgs e) {
}
However, you would need to recognize each button based on the sender parameter. For that, you can use the
Tag
property. Define a proper Tag on each button and then in the event handler check the tag of the button that is the sender.
But... I don't quite see the benefit from this. If you want to do this because you have a lot of common code for each button, I would still use a separate event handlers. Each event handler would then call a common or multiple common methods to do the actual operations. These methods can reside on the window class or another class if appropriate. This way you wouldn't mix the user interface to the logic (again if the assumption about the common code was true :)).