Speed โ€‹โ€‹up on / off controls (C # WinForms)

I have a recursive method in basic form that accepts a control and an enabled flag. It passes through each control in the form and based on what type of control it is, it accordingly sets the background color of the control and sets the enabled property to the parameter.

So, as a rule, a method is called passing (this) as a control, it goes through all the controls and their controls and sets things accordingly. This works fine, but the forms have more and more controls added to them, you can see that the controls are disabled one by one, and it doesn't look good.

Does anyone have an idea how I can either rewrite this or prevent him from demonstrating the shutdown process on each control one by one? Something like SuspendLayout that will work in this case? Itโ€™s not possible to add a panel to the form and simply turn it off and turn it back on at the end, because I have about 200+ forms that are inherited from this basic form and cannot go through each of them and make it add controls to the panel . This also will not work, because it is not only a matter of enabling / disabling controls, but also applying different logic to them.

+3
source share
2 answers

Make changes to:

form.SuspendLayout();

and

form.ResumeLayout(false); // read the doc about "false", might be a little unsafe

, . .

+7

OnPaint super:: OnPaint, (IsDoneDisabling = true). .

OnPaint(...)
{
if (IsDoneDisabling)
    super::OnPaint(...);
}
-3

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


All Articles