I am having a user control with a flow layout panel. This control can have one or more same controls. This hierarchy can grow to many levels.
Initially I am adding the Root Control. Then Controls are added to the root control (flow layout panel).
private void Form2_Load(object sender, EventArgs e)
{
SuspendLayout();
AddControls(containerControl1, _rootFileNode.Nodes);
ResumeLayout(false);
PerformLayout();
}
private void AddControls(IContainerNode parent, ICollection<INode> childNodes)
{
foreach (var node in childNodes)
{
switch (node.FileType)
{
case FileType.File:
parent.AddNode(node);
break;
case FileType.Directory:
{
var container = parent.AddNode(node) as IContainerNode;
AddControls(container, node.Nodes);
break;
}
}
}
}
Code which actually adds the control (ContainerControl class).
public DesignerBase AddNode(INode node)
{
//Get the corresponding Control
//Simple User Control with label and RTF- If File Node
//User Control with FlowLayout and other controls - If Folder Node
var designerBlock = DesignerBlockFactory.Get(node);
flowLayoutMain.Controls.Add(designerBlock);
return designerBlock;
}
The problem is, I am having multiple levels of controls. But it seems that the immediate container inside the root container is not resizing properly. And so the nodes are partially shown. If I enable the AutoResize property of the user controls then the User Control is resizing but with bad flickering.
Is there any way to force the contrpls to resize immediately. I tried Suspend layout in the Form and also in the User Control
Fix: I did not actually fix this issue. I enabled auto resize property to true. This caused bad flickering during form load.
To reduce the flicker, I added the following code in the Form.
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
This will show the form once all the controls are loaded. So there will be an initial delay before the form load.