Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BeginUpdate() EndUpdate for a UserControl

I have written a UserControl that behaves like a ContainerControl, but is totally painted by WindowsForms (I inherit from UserControl)

I would like to avoid painting the control while I'm filling it, so I would need to write something similar to BeginUpdate() - EndUpdate().

This is easy to do when the control is user-painted, but in this case I'm not sure about how to proceed.

like image 896
Daniel Peñalba Avatar asked Feb 14 '11 15:02

Daniel Peñalba


1 Answers

You could make use of Suspend/Resume layout. e.g.

private void BeginUpdate()
{
  this.SuspendLayout();
  // Do paint events
  EndUpdate();
}

private void EndUpdate()
{
   this.ResumeLayout();
   // Raise an event if needed.
}

If you're interested in suspending the painting of a control and it's children, check out this SO question: Suspend Control and Children Painting

like image 157
George Johnston Avatar answered Oct 10 '22 04:10

George Johnston