更新时间:2023-12-06 09:04:40
SuspendLayout()
和 ResumeLayout()
不挂起图纸,只是布局操作。给这家伙一个镜头:
SuspendLayout()
and ResumeLayout()
do not suspend drawing, only layout operations. Give this guy a shot:
public static class ControlHelper
{
#region Redraw Suspend/Resume
[DllImport("user32.dll", EntryPoint = "SendMessageA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
private const int WM_SETREDRAW = 0xB;
public static void SuspendDrawing(this Control target)
{
SendMessage(target.Handle, WM_SETREDRAW, 0, 0);
}
public static void ResumeDrawing(this Control target) { ResumeDrawing(target, true); }
public static void ResumeDrawing(this Control target, bool redraw)
{
SendMessage(target.Handle, WM_SETREDRAW, 1, 0);
if (redraw)
{
target.Refresh();
}
}
#endregion
}
用法应该是不言自明的,而语法等同于 SuspendLayout()
和 ResumeLayout()
。这些扩展方法,将显示在控制的任何实例。
Usage should be pretty self-explanatory, and the syntax is identical to SuspendLayout()
and ResumeLayout()
. These are extension methods that will show on any instance of Control.