【问题标题】:Suspend/resume painting of treeview's scrollbars暂停/恢复树视图滚动条的绘制
【发布时间】:2012-10-10 03:28:52
【问题描述】:

我试图在重绘树视图时阻止树视图的垂直滚动条闪烁。我已经有一个自定义树视图控件,它可以使用 WndProc 禁用绘画,它适用于树视图本身,但不会阻止树视图的滚动条在我清除/创建树视图中的节点时重新绘画和闪烁。

有什么解决办法吗?以下是自定义树视图中的代码:

    private bool enablePaint = true;
    protected override void WndProc(ref Message m)
    {
        switch (m.Msg)
        {
            case WM_PAINT:
                if (enablePaint)
                    base.WndProc(ref m);
                break;
            case WM_ERASEBKGND:
                break;
            default:
                base.WndProc(ref m);
                break;
        }
    }

感谢您的帮助。

【问题讨论】:

    标签: c# treeview repaint scrollbars redraw


    【解决方案1】:

    我找到了解决方案,使用 LockWindowUpdate:

        [DllImport("user32.dll")]
        private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
        [DllImport("user32.dll")]
        private static extern bool LockWindowUpdate(IntPtr hWndLock);
        public new void BeginUpdate()
        {
            SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)0, IntPtr.Zero);
            LockWindowUpdate(this.Handle);
        }
        public new void EndUpdate()
        {
            LockWindowUpdate(IntPtr.Zero);
            SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)1, IntPtr.Zero);
        }
    

    【讨论】:

    • 我很确定 SuspendLayout 和 ResumeLayout 在“幕后”使用 LockWindowUpdate。不过我可能是错的。
    • 我试过了,即。用它们替换了 LockWindowUpdates,但垂直滚动条闪烁。 LWU 是我发现的唯一可行的解​​决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-09
    • 2011-07-31
    • 2015-04-18
    相关资源
    最近更新 更多