开发者

How to force paint after setting Enabled = false in a C# windows usercontrol, not WPF?

开发者 https://www.devze.com 2023-01-22 18:11 出处:网络
How开发者_StackOverflow社区 to force paint after setting Enabled = false in a C# windows usercontrol ?Use EnabledChange event for the UserControl..

How开发者_StackOverflow社区 to force paint after setting Enabled = false in a C# windows usercontrol ?


Use EnabledChange event for the UserControl..

private void userControl_EnabledChanged(object sender, EventArgs e)
{
    if (! Enabled)
        Invalidate(); // ask the control to redraw itself
}

Note: put this code inside the userControl class, not in the form. Good luck!


If you are using winforms:

myControl.Invalidate();
myControl.Update();


If you're talking about WPF UserControls, you can just subscribe to the IsEnabledChanged event of your control and call InvalidateVisual() in the event handler.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号