Change user control properties based on the Enabled property

In .NET C # 3.5 Winforms, I have a user control using some simple child controls, such as text fields, labels, and buttons. Currently, when I set the property of the .Enableduser control to false, the controls are fading accordingly. However, if I use custom .BackColorfor a user control, sometimes the dimming is not as obvious as I would prefer.

Is there a way to specify or change the dimming color of a user control if the parameter is .Enabledset to false? Or according to the corresponding note, is there a way I can call a method when this happens?

+3
source share
3 answers

The controls have an EnabledChange event to which you can connect. Create a handler for this event for the user control and change its properties accordingly.

+4
source

.OnEnabledChanged(EventArgs e), EnabledChanged, , .Enable, :

protected override OnEnabledChanged(EventArgs e)
{
    base.OnEnabledChanged(e);
    // your code here
}
+2

, , ( ).

, :

public new bool Enabled
{
    get
    {
        return base.Enabled;
    }
    set
    {
        base.Enabled = value;
        // code to alter the appearance of control
    }
}

EDIT:

, Enabled. :

this.EnabledChanged += new EventHandler(UserControl_EnabledChanged);
void UserControl_EnabledChanged(object sender, EventArgs e)
{
    // code to alter appearance of control
}
0

Source: https://habr.com/ru/post/1748439/


All Articles