-1

I'm using "FlowLayoutPanel" to store a complex GUI. This structure contains two types of UserControls:

  1. "S" Simple U.C (Constant Size)
  2. "C" Another FlowLayoutPanel that can have those to type as childs.. and so on.

When I have this kind of structure:

1.C

  1. S
  2. S
  3. C :

    1.s

    2.C

       1.S
       2.S
    

It takes about 15 sec to render this control, Every time this control visble changes the GUI get stuck for 15+- sec until its render the whole components.

*Note 1: the complex "C" control is auto sized which contains the FlowLayoutPanel. all "inner" "C" components get their height changed when adding childs. the main\master "C" control got a fix size and have scroll bar.

*Note 2: I extended the FlowLayoutPanel to have some double buffered optimizations:

public sealed class FlowLayoutPanelEx : FlowLayoutPanel {

    public FlowLayoutPanelEx()
        : base()
    {
        this.SetStyle(ControlStyles.UserPaint, true);
        this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
        this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
    }

    protected override void OnScroll(ScrollEventArgs se)
    {
        this.Invalidate();

        base.OnScroll(se);
    }

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x02000000; // WS_CLIPCHILDREN
            return cp;
        }
    }

}
Aviram Fireberger
  • 3,910
  • 5
  • 50
  • 69

1 Answers1

0

Solved by overriding the "SuspendLayout" and "ResumeLayout" functions,

When I need to paint this control and nothing changed, I call the SuspendLayout function which calls the "SuspendLayout" function for each child recursivly.

After the paint is over. I call the "ResumeLayout" which does the same.

This will make the user control not to "RePaint" and calculate all the childs\parent size, and just paint the control at the same state he was before.

Reduce the rendering time from 15 Sec to 0.2 Sec :)

Aviram Fireberger
  • 3,910
  • 5
  • 50
  • 69