We use a large amount of thrid party controls in our UIs however some of these do not always behave as expected and ignore BeginInit/BeginUpdate/SuspendLayout.
I came across this work around for this problem the other day:
[DllImport("User32")]
private static extern bool SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
int m_paintFrozen = 0;
private bool FreezePainting
{
get { return m_paintFrozen > 0; }
set
{
if (value && IsHandleCreated && this.Visible)
{
if (0 == m_paintFrozen++)
{
SendMessage(Handle, WM_SETREDRAW, 0, 0);
}
}
if (!value)
{
if (m_paintFrozen == 0)
{
return;
}
if (0 == --m_paintFrozen)
{
SendMessage(Handle, WM_SETREDRAW, 1, 0);
Invalidate(true);
}
}
}
}
You can then force a control to stop painting by setting FreezePainting to true, just remember to do it inside of a
try - finally block so you are sure you turn it back on..