0

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.

Rajan Panneer Selvam
  • 1,279
  • 10
  • 24
  • I think your ResumeLayout(false); PerformLayout(); may be in the wrong order, try switching those and see what happens. – Glenn Cuevas Jul 29 '13 at 17:26
  • Does it works when you supsend/resume the layout of the parent node inside the AddControls: parent.SuspendLayout() and parent.ResumeLayout() – Martijn van Put Jul 29 '13 at 18:28
  • No.. Its still not working.. I tried the following case FileType.File: (parent as UserControl).SuspendLayout(); parent.AddNode(node); (parent as UserControl).ResumeLayout(false); (parent as UserControl).PerformLayout(); break; case FileType.Directory: { (parent as UserControl).SuspendLayout(); var container = parent.AddNode(node) as IContainerNode; (parent as UserControl).ResumeLayout(false); parent as UserControl).PerformLayout(); AddControls(container, node.Nodes); break; } – Rajan Panneer Selvam Jul 29 '13 at 19:13
  • Well, maybe we can tweak the design a little bit, move the code out of Form2_Load and into Form2's constructor after the InitializeComponent call, that way all of the rendering should be complete and all we need to wait for is the painting of it. – Glenn Cuevas Jul 29 '13 at 20:37
  • Still no change.. As I mention earlier, initially the controls are overlapped.. I suspect the width and the height is not calculated properly.. After few resizing it renders correctly.. I have implemented a method that will recusrively set the Height of the controls and its working.. Still looking for a proper solution.. – Rajan Panneer Selvam Jul 29 '13 at 20:50
  • Looks like we have [the same issue](http://stackoverflow.com/questions/19834687/top-docking-controls-more-than-32768-pixels): when docking controls with a total height over 32768 pixels, the lower controls no longer dock properly. – Martin Nov 07 '13 at 14:57
  • See my update. Please share your answer if you have fixed this. – Rajan Panneer Selvam Nov 08 '13 at 05:12

0 Answers0