Suspend or resume windows controls to be redraw

Recently, I was facing issue with third party Image Viewer to apply multiple operations before redrawing of images.
Third-party control was not allowing to suspend and resume painting of images inherently. After searching for various solutions, I found a solution that can be achieved using windows message WM_SETREDRAW from an application to Windows to allow changes in that control to be redrawn or to prevent changes in that control from being redrawn.

public class UIDrawController
public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);

private const int WM_SETREDRAW = 11;

public static void SuspendDrawing(Control ctrl)
SendMessage(ctrl.Handle, WM_SETREDRAW, false, 0);

public static void ResumeDrawing(Control ctrl)
SendMessage(ctrl.Handle, WM_SETREDRAW, true, 0);

Example Usage:

public ImageViewer : UserControl

public void LoadDocument(string filename)





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s