How can I make DoubleBuffer winforms Treeview?

I have a standard treeview winforms control that flickers whenever I hover over any other form element. I would like doubleBuffer to see a tree to reduce flicker, but I have no idea how to do this. Can someone show me how to achieve my goal?

Many thanks

+3
source share
4 answers

TreeView, - . TreeView .NET , :

 Public Class DoubleBufferedTreeView
    Inherits System.Windows.Forms.TreeView

    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
        Me.UpdateStyles()
    End Sub
End Class

, , , - , , TreeNodes, - , .

DoubleBuffering , TreeView , , . TreeView, , , TreeView , , , .

PS. #.

+1

, #, . DoubleBuffer Control. , . , .

public sealed class MyNonFlickringTreeView:Treeview
{
 public MyNonFlickringTreeView()
   {
      this.DoubleBuffered=true;
   }
}
0

, Int3 , , , .

You need to call SuspendLayout first to stop creating the full contents of the tree in the user interface. When processing is complete, you start the layout logic again with ResumeLayout (). The MSDN documentation for SuspendLayout with sample code is here .

private void buildTreeContent()
{
   // Suspend the form layout and add two buttons.
   this.SuspendLayout();

   // Do your work here
   // ...

   // Make the Form do paint the layout again.
   this.ResumeLayout();
}

This should help a lot of flickering, since creating a tree element is resource intensive, we have done this many times in our projects.

An alternative approach is to work with Windows messaging. This is explained in more detail in another SO thread .

0
source

All Articles