My application has the following UI configuration:
The main form is an MDI container. Its child forms are attached to a TabStrip.
Each user has his set of child forms. Depending on the active user, only that user’s child forms are displayed, together with tabs.
This is achieved by going through the main form’s MdiChildren and setting their Visible property to 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 undesired effects. One is that every child form gets redrawn in succession, which is ugly and slow. The other is that for some reason the forms go from maximized to normal, effectively undocking them from the main form.
Is there any way to display just one of the child forms, such as the one the user was previously looking at, and get the others to stay in the background? The maximize/normal thing is not that big a deal because I can maximize them again manually.
I eventually solved this one so here’s a belated write-up.
Will Marcouiller suggested
SuspendLayout()andResumeLayout(), which did not work. This led me to investigate what these two methods actually do and reach the conclusion that what I needed was a way to stop the main form from redrawing while operations on the MDI children were in progress.This in turn resulted in the following two static utility methods which suspend redrawing for a given control. In my case, suspending redrawing of the main form resulted in a massive speed up.