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?

Re: Adding Event Handlers to Inherited Controls by Kevin

Kevin
Fri Dec 21 05:50:54 CST 2007

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

"stuppi" <stuppi@discussions.microsoft.com> wrote in message
news:C8677178-99F1-4130-B486-305BF406381F@microsoft.com...
>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?
>