views:

44

answers:

3

We know that when a Form is visually inherited, all of its controls are locked in design time. This problem requires that we place event handlers in the base form. Now what should I do if I want to place base-control event handlers in the derived Form?

Since the controls are locked, approach of double clicking on the control to add an event-handler should not work.

What is the industry-standard approach for event handling in case of Visual Inheritance?

+2  A: 

You handle the event on the base Form and use it to call a virtual method. The derived Form overrides that method.

Henk Holterman
+1 for that. The base controls should be as isolated as possible, and all access should be through virtual methods / implkemented private methods for upward access.
TomTom
+1  A: 

The designer honors the access modifiers on the base class members. You must change the Modifiers property of the base form's control from Private to Protected. Recompile. Now the inherited form has access to the control, you'll have no trouble overriding properties and assigning an event handler from the designer.

Hans Passant
changing access control might lead to changes in design, and that's more the some people would like to do.
Neowizard
Right-click the control and click Lock Controls. They don't have to change the design if they don't like to, this ought to be obvious.
Hans Passant
A: 

Another method is to add an event in the user control (instead of a virtual method) and then fire it when the internal event is fired.

Neowizard