I do not find a good explanation on what actually the underlying difference is between the two methods Control.SuspendLayout
and BeginUpdate
(typically seen on list controls like ListView
, ComboBox
, ListBox
etc), other than that they both improve performance.
From what I understand:
they both suspend drawing until all the items to display are loaded, and repaint after that.
typically SuspendLayout
is called when controls are added to container controls like Panel
, GroupBox
etc, while BeginUpdate
is used for adding non-control items like objects to list controls like ListBox
.
But why are there two calls when they do the same? Or what do they do differently?
Similarly there is ResumeLayout
and EndUpdate
equivalents.
They have nothing in common. SuspendLayout turns off automatic layout, the kind that's used by controls like TableLayoutPanel and FlowLayoutPanel as well as the layout updates you get from the Dock, Anchor and AutoSize properties. It has no effect at all on ListView, ComboBox or ListBox, those controls don't perform layout. You typically only use it when you add controls in bulk to a container. Sometimes you use it when automatic layout makes resizing the window too obnoxious. It does reduce the number of repaints, solely by the fact that it suspends control size updates.
BeginUpdate stops a control from repainting itself. You do use it on controls like ListView or ListBox when you add items to them in bulk and can't use their Items.AddRange() method for some reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With