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)
I’m not really in Windows and stuff, but judging by what MSDN says about that flag, it doesn’t do what you think it does. It’s used to disable redrawing controls (think a list view) while you change their contents. Disabling it inside the redraw function is probably not going to do anything.
See if you can find something related to “double buffering”, because that’s one technique used to avoid flicker.