I’m working on an form custom control.the control is a MonthCalendar like Visual studio(C#) MonthCalendar control and I want to define an event for my control.
How can define a new event for this form custom control?
I’m working on an form custom control.the control is a MonthCalendar like Visual studio(C#)
Share
If your event should not provide any additional info (Foo is name of your event):
And raise it this way:
If you need to pass some additional info to event handlers, then create custom arguments class by inheriting from
EvenArgsclassDeclare event this way:
And raise it this way:
Its good practice to create protected methods for raising events by descendants of class where event is declared. Also good practice to use event naming convention:
-ingto event name for events which raised beforesomething happened (often you could cancel such events) (e.g. Validating)
-edto event name for events which raised after something happened (e.g. Clicked)As Thorsten stated, good practice to create
virtualmethods for raising events. Its not only allows to raise events from descendants, but also disable event raising, or adding some behavior prior/after event raising.