How to disable all screen refreshes ?

J

JezB

I do some fairly complex manipulations of many of the controls on my form,
including location and size (even the size of the form itself). I want to
disable all screen refreshes until all this is complete, and just display
the result at the end. How can I do this? SuspendLayout/ResumeLayout does
not do the job.
 
J

JezB

Don't worry I found it:

#region FreezePainting
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);
}
}
}
}
#endregion

then just set FreezePainting to true/false as needed in the form.
 
G

Gabriel Lozano-Morán

I was about to say that you could look usign reflection at the implemantion
of the ListBox BeginUpdate/EndUpdate but I'm glad you already found
something similar.

Gabriel Lozano-Morán
 
J

JezB

Problem is with this method: when painting is frozen quite often screen
objects behind my form SHOW THROUGH the form which does not look good at
all!

JezB said:
Don't worry I found it:

#region FreezePainting
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);
}
}
}
}
#endregion

then just set FreezePainting to true/false as needed in the form.

JezB said:
I do some fairly complex manipulations of many of the controls on my form,
including location and size (even the size of the form itself). I want to
disable all screen refreshes until all this is complete, and just display
the result at the end. How can I do this? SuspendLayout/ResumeLayout does
not do the job.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top