Shawn Burke responded to this question in a posting on microsoft.public.dotnet.framework.windowsforms newsgroup.
There is not currently a way to do this built into the framework, but WM_SETREDRAW will do what you’re looking for. It can’t be called recursively, so here’s code for a property you can add to your form to handle it. A VB sample is also available.
int paintFrozen;
private const int WM_SETREDRAW = 0xB;
[DllImport(''User32'')]
private static extern bool SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
private bool FreezePainting
{
get { return paintFrozen > 0; }
set {
if (value && IsHandleCreated && this.Visible)
{
if (0 == paintFrozen++)
{
SendMessage(Handle, WM_SETREDRAW, 0, 0);
}
}
if (!value)
{
if (paintFrozen == 0)
{
return;
}
if (0 == --paintFrozen)
{
SendMessage(Handle, WM_SETREDRAW, 1, 0);
Invalidate(true);
}
}
}
}
Permalink