I’ve looked around a bit and I can’t come up with an answer on how to effectively “override” the Control.Enabled in C# WinForms 3.5.
Our situation is that we have a base form or master form that we use which adds a status bar at the bottom and toolbar at the top. This form becomes inherited by all our other forms then which then add controls to the center panel.
On some of the forms that inherit from the master base form, we want to be able to use the “Enabled” property on the form but we want to be able to override the funcionality so it only disables the center panel and not the status/menu bar and so it can still move the form around.
I have tried to do the following on the master form (FrmBaseStatus):
private bool enabled = true;
public new bool Enabled
{
return this.enabled;
}
set
{
this.enabled = value;
this.panelBase.Enabled = value;
}
However obviously this is not a true override and if we have a user control on the base panel in one of our inherited forms and we want to override the form from this user control we have to do something like:
((FrmBaseStatus)this.ParentForm).Enabled = true;
Is there any other way to do this or are we stuck with always casting to our base form in order to reach the Enabled property we want to use.?
Note: Would overriding the OnEnabled event and not calling the base OnEnabled do this or is the enabling and disabling not done in this event of Control.OnEnabled()?
The
Enabledproperty in a control is used to enable/disable the whole control, so I don’t understand exactly why you need to override theEnabledproperty on your parent form. If you need to disable exactly the centerPanel, add a property to get that panel, and disable it.I would recommend defining a
CenterPanelproperty in your base form, and then use it to disable that panel:Then from your inherited forms you could use: