1

I remove and add a lot of controls dynamically to a form. How can I redraw the GUI only once?

After each removing or adding of a control it is redrawn.

daniel
  • 34,281
  • 39
  • 104
  • 158

1 Answers1

2

If you're creating the elements in code, you probably want to use SuspendLayout function of the Form.

this.SuspendLayout();

// Bulk add the elements to the Form controls.

this.ResumeLayout();

From the documentation:

The layout logic of the control is suspended until the ResumeLayout method is called. The SuspendLayout and ResumeLayout methods are used in tandem to suppress multiple Layout events while you adjust multiple attributes of the control. For example, you would typically call the SuspendLayout method, then set the Size, Location, Anchor, or Dock properties of the control, and then call the ResumeLayout method to enable the changes to take effect. There must be no pending calls to SuspendLayout for ResumeLayout to be successfully called.

msmolcic
  • 6,407
  • 8
  • 32
  • 56