I need to design a custom control that is basically going to be a fancy button, let’s call it CtrlButton.
I want to drop these on my blank form, then go to the Events for my control and specify what to do for the Click event.
If my custom control CtrlButton contained 1 Windows Form Button named button1, could I simply expose the underlying Click event handler for the button1?
public EventHandler Click {
get { return button1.Click; }
set { button1.Click = value; }
}
This code doesn’t work! But, that’s essentially what I’m trying to do.
EDIT: I see I was awarded Popular Question for this post, yet it still sits there at -1. If this question helps you find your answer, please vote it up.
Button.Click is an event, not a property. You can’t get and set its value, because it’s not a property; you can only add and remove handlers, because it’s an event and that’s how events work.
But you can write your own event with custom
addandremovehandlers that wrap the Button: