Effectively Override Control.Enabled

I looked around a bit and can not answer the question of how to effectively "override" Control.Enabled in C # WinForms 3.5.

Our situation is that we are using a basic form or a basic form that adds a status bar at the bottom and a toolbar at the top. This form is inherited by all our other forms, and then adds controls to the central panel.

In some forms that inherit from the main base form, we want to be able to use the "Enabled" property in the form, but we want to redefine the functionality so that it only disables the center panel, and not in the status bar / menu, and thus it can move the form.

I tried to do the following in the main form (FrmBaseStatus):

private bool enabled = true; public new bool Enabled { return this.enabled; } set { this.enabled = value; this.panelBase.Enabled = value; } 

However, this is obviously not a true redefinition, and if we have a user control in the base panel in one of our inherited forms, and we want to redefine the form from this user control, we should do something like:

 ((FrmBaseStatus)this.ParentForm).Enabled = true; 

Is there any other way to do this, or are we fixated on always discarding our base form in order to achieve the Enabled property we want to use.

Note. Does this event replace OnEnabled and do not call the base function OnEnabled, or does this enable and disable fail in this case Control.OnEnabled ()?

+4
source share
1 answer

The Enabled property in the control is used to enable / disable the entire control, so I donโ€™t understand why you need to override the Enabled property in your parent form. If you need to disable centerPanel, add a property to get this panel, and disable it.

I would recommend defining the CenterPanel property in your base form, and then use it to disable this panel:

 // code defined in your FrmBaseStatus form protected Control CenterPanel { get { return this.panelBase; } } 

Then from your inherited forms you can use:

 // disable center panel and its childs this.CenterPanel.Enabled = false; //disable the whole form this.Enabled = false; 
+4
source

All Articles