基本上我已经设置了一个类来处理发送 WM_SETREDRAW 消息,如下所示:
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);
}
}
然后我在我的自定义用户控件中有一个 Redraw 方法:
public void Redraw()
{
try
{
DrawingLocker.LockDrawing(Handle);
using (Graphics graphics = Graphics.FromHwnd(Handle))
{
//Draw Stuff
}
}
finally { DrawingLocker.UnlockDrawing(Handle); }
}
我的问题是,我没有在“Draw Stuff”注释所在的位置绘制任何内容。我究竟做错了什么?(当影响绘图的值发生变化时调用重绘,包括调整大小)