2012-10-10 26 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