Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing properties on user control based on Enabled property

Tags:

c#

winforms

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?

like image 388
JYelton Avatar asked Jun 03 '10 23:06

JYelton


2 Answers

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.

like image 86
Anthony Pegram Avatar answered Sep 28 '22 02:09

Anthony Pegram


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
}
like image 39
max Avatar answered Sep 28 '22 03:09

max