In .NET C# 3.5 Winforms, I have a user control with some simple child controls such as textboxes, labels, and buttons. Currently when I set the .Enabled
property of the user control to false, the controls dim accordingly. However, if I use a custom .BackColor
for the user control, sometimes the dimming is not as apparent as I would prefer.
Is there a way to specify or change the dimming color of the user control when .Enabled
is set to false? Or on a related note, is there a way I can call a method when this happens?
Controls have an EnabledChange event you can tap into. Create a handler for this event for the user control and change its controls' properties accordingly.
You can override .OnEnabledChanged(EventArgs e)
method if you dont want to subscribe to EnabledChanged
event, and it's a better solution than hiding Control's .Enable
property, which is not marked virtual:
protected override OnEnabledChanged(EventArgs e)
{
base.OnEnabledChanged(e);
// your code here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With