I have a FlowLayoutPanel that contains 56 checkboxes. The checkboxes are used in three state mode. Now here is the fun part. If the check boxes are uncheked that means that they are not used and can be hidden for ease or reading. To hide them I use another checkbox. When to user clicks the checkbox all unused checkboxs in the FlowPanel are hidden using a foreach iteration.
The problem is that to hide them, that foreach call take (checkBox.Visible=false) about 2-3 seconds and to show them (checkBox.Visible=true) takes 0.5 seconds.
Any suggestions as to why this is happening?
private void hideUnusedPinsCheckBoxClick(objest sender, EventArgs e)
{
bool state = !hideUnusedPinsCheckBox.Checked;
foreach(object obj in flowLayoutPanel.Controls)
{
CheckBox cB = (CheckBox)obj;
if(cB.CheckState == CheckState.Unchecked)
cB.Visible=state;
}
}
You could try calling
SuspendLayoutbefore hiding all your checkboxes, and then callingResumeLayoutafterwards. See this link for more.The answer your question as to why this is happening. Each time you hide (or show) a control on the FlowLayoutPanel, the panels layouter algorithm is executed in order to rearrange everything on screen. If you hide for example 50 check boxes in a row, the layouter algorithm will execute at least 1,275 times. For example:
By calling SuspendLayout, the layouter algorithm does not run at all until you call ResumeLayout, reducing the number from 1,275 to 1.