且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows窗体:使用的BackgroundImage减慢窗体的控件的绘制

更新时间: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.