2012-10-10 12 views
1

我试图在重绘树状图时停止TreeView的垂直滚动条闪烁。我已经有了一个自定义的treeview控件,它可以使用WndProc来禁用绘画,并且它对treeview本身工作正常,但是无论何时我在treeview中清除/创建节点时都不会停止重绘和闪烁的treeview滚动条。树状图的滚动条挂起/恢复绘画

有没有解决这个问题的方法?这里是自定义树视图的代码:

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; 
     } 
    } 

感谢您的任何帮助。

回答

-2

我找到了解决方案,使用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); 
    } 
+0

我敢肯定SuspendLayout和ResumeLayout使用LockWindowUpdate “幕后”。但我可能是错的。 –

+0

我试过那些,即。用他们替换LockWindowUpdates,但垂直滚动条闪烁。 LWU是我发现的唯一解决方案。 – giangurgolo

+0

-1不包含'private const int WM_SETREDRAW = 0xB;' – toddmo