I have an ordinary Panel control with a bunch of user controls contained within. At the moment, I do the following:
panel.Controls.Clear();
but this has the effect that I see (albeit quickly) each control disappearing individually.
Using SuspendLayout
and ResumeLayout
does not have any noticeable effect.
Question: Is there a way I can remove ALL controls, and have the container update only when all child controls have been removed?
Edit: the controls I am removing are derived from UserControl, so I have some control over their drawing behaviour. Is there some function I could possibly override in order to prevent the updating as they are removed?
Thank you Hans for your suggestion - yes, it turns out I was leaking controls.
Here's what I ended up doing:
panel.Visible = false;
while (panel.Controls.Count > 0)
{
panel.Controls[0].Dispose();
}
panel.Visible = true;
Basically, I hide the entire panel (which is border-less) before I dispose of each control. Disposing of each control automatically removes said control from the parent container, which is nice. Finally, I make the container visible once more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With