Mdi child slows down slowly when visibility changes

My application has the following user interface configuration:

The main form is an MDI container. Its child forms are attached to TabStrip.

Each user has his own set of child forms. Depending on the active user, only the child forms of the user are displayed along with the tabs.

This is achieved by going through the main form MdiChildrenand setting their properties Visiblein false/true, depending on the active user.

        foreach (Form item in MdiChildren)
        {
            if (((OfficeFormEx)item).UserID == (int)e.NewTab.Tag)
            {
                item.Visible = true;
            }
            else
            {
                item.Visible = false;
            }
        }

This has two undesirable effects. First, each child form is redrawn sequentially, which is ugly and slow. Another thing is that for some reason the forms go from maximized to normal, effectively undocking them from the main form.

, , , ? / , .

+3
3

, .

SuspendLayout() ResumeLayout(), . , , , , , - , MDI.

, , , . .

/// <summary>
/// suspends drawing on a control and its children
/// </summary>
/// <param name="parent"></param>
public static void SuspendDrawing(Control control)
{
    SendMessage(control.Handle, WM_SETREDRAW, false, 0);
}

/// <summary>
/// resumes drawing on a control and its children
/// </summary>
/// <param name="parent"></param>
public static void ResumeDrawing(Control control)
{
    SendMessage(control.Handle, WM_SETREDRAW, true, 0);
    control.Refresh();
}
+1

, Form.WindowsState, . , FormWindowState.Maximized , Visible true/false.

"[...] [...]" - , SuspendLayout() ResumeLayout()?

№ 1

  • Form .

, , , MdiChildren. , , .

, , Linq :

var visibleForms = from f in MdiChildren
                   where (((OfficeFormEx)f).UserID == (int)e.NewTab.Tag)
                   select f;

var invisibleForms = from f in MdiChildren
                     where (((OfficeFormEx)f).UserID != (int)e.NewTab.Tag)
                     select f

visibleForms.ToList().ForEach(f => f.Visible = true);
invisibleForms.ToList().ForEach(f => f.Visible = false);

.NET 4.0, , PLINQ

, . =)

+2

. Windows MDI. , , , . Windows Forms Visible, Window, , Visible True. .

, . WF , .

MDI . , TabControl UserControls .

+2
source

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


All Articles