I have a control which I have to make large modifications to. I\'d like to completely prevent it from redrawing while I do that - SuspendLayout and ResumeLayout aren\'t eno
I usually use a little modified version of ngLink's answer.
public class MyControl : Control
{
private int suspendCounter = 0;
private void SuspendDrawing()
{
if(suspendCounter == 0)
SendMessage(this.Handle, WM_SETREDRAW, false, 0);
suspendCounter++;
}
private void ResumeDrawing()
{
suspendCounter--;
if(suspendCounter == 0)
{
SendMessage(this.Handle, WM_SETREDRAW, true, 0);
this.Refresh();
}
}
}
This allows suspend/resume calls to be nested. You must make sure to match each SuspendDrawing
with a ResumeDrawing
. Hence, it wouldn't probably be a good idea to make them public.