Basically I've set up a class to handle sending WM_SETREDRAW messages like so:
public static class DrawingLocker
{
[DllImport("user32", CharSet = CharSet.Auto)]
private extern static IntPtr SendMessage(IntPtr hWnd,
int msg, int wParam, IntPtr lParam);
private const int WM_SETREDRAW = 11; //0xB
public static void LockDrawing(IntPtr Handle)
{
SendMessage(Handle, WM_SETREDRAW, 0, IntPtr.Zero);
}
public static void UnlockDrawing(IntPtr Handle)
{
SendMessage(Handle, WM_SETREDRAW, 1, IntPtr.Zero);
}
}
I then have a Redraw method in my custom user control:
public void Redraw()
{
try
{
DrawingLocker.LockDrawing(Handle);
using (Graphics graphics = Graphics.FromHwnd(Handle))
{
//Draw Stuff
}
}
finally { DrawingLocker.UnlockDrawing(Handle); }
}
My problem is that nothing I draw where the "Draw Stuff" comment is gets drawn. What am I doing wrong? (Redraw gets called when values that effect drawing change, including resize)