Adding Event Handlers to Inherited Controls

  • Thread starter Thread starter stuppi
  • Start date Start date
S

stuppi

I often create classes that inherit from standard controls in order to handle
certain events in a consistent manner. Being a novice propononet of
encapsulation, I add the event handlers in the constructor of the derived
class. However, as many of you have probably discovered, this can create
problems with WinForms and the VS forms designer if those event handlers rely
on runtime conditions. Can anyone suggest a "designer safe" place to add the
event handlers within the derived class?
 
The System.Windows.Forms.Control (and all inherited classes, therefore)
class has a property called "DesignMode" which is a boolean value. If you
don't want to run code in the designer, use a test for DesignMode to prevent
it from running.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 
Back
Top