Adding Event Handlers to Inherited Controls

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?
 
K

Kevin Spencer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top