Articles in this section
Category / Section

How to apply gradient style to TreeNodeAdv in WinForms TreeViewAdv?

2 mins read

Gradient style

The appearance of WinForms Treeview can be customized by using the class named “TreeNodeAdvStyleInfo”. For example, it is possible to customize TreeNodeAdv in Gradient appearance, by using class named “TreeNodeAdvStyleInfo”.

C#

//The list of the colors gradient color
BrushInfoColorArrayList Brush1 = new BrushInfoColorArrayList();
Brush1.Add(Color.Yellow);
Brush1.Add(Color.Gray);
 
BrushInfoColorArrayList Brush2 = new BrushInfoColorArrayList();
Brush2.Add(Color.Yellow);
Brush2.Add(Color.Green);
Brush2.Add(Color.LightGray);
 
BrushInfoColorArrayList Brush3 = new BrushInfoColorArrayList();
Brush3.Add(Color.Yellow);
Brush3.Add(Color.Green);
Brush3.Add(Color.LightGray);
 
//To set the Back ground color for TreeNodeAdvStyleInfo'
treeNodeAdvStyleInfo1.Background = new Syncfusion.Drawing.BrushInfo(GradientStyle.PathEllipse, Brush1);
//To set the Text color for TreeNodeAdvStyleInfo
treeNodeAdvStyleInfo1.TextColor = Color.WhiteSmoke;
 
treeNodeAdvStyleInfo2.Background = new Syncfusion.Drawing.BrushInfo(GradientStyle.ForwardDiagonal, Brush2);
treeNodeAdvStyleInfo2.TextColor = Color.Yellow;
 
treeNodeAdvStyleInfo3.Background = new Syncfusion.Drawing.BrushInfo(GradientStyle.BackwardDiagonal, Brush3);
treeNodeAdvStyleInfo3.TextColor = Color.Brown;
 
//To add TreeNodeAdvStyleInfo into TreeViewAdv BaseStyle
this.TreeViewAdv1.BaseStylePairs.AddRange(new Syncfusion.Windows.Forms.Tools.StyleNamePair[] {
    new Syncfusion.Windows.Forms.Tools.StyleNamePair("BaseStyle1", treeNodeAdvStyleInfo1), new Syncfusion.Windows.Forms.Tools.StyleNamePair("BaseStyle2", treeNodeAdvStyleInfo2),
    new Syncfusion.Windows.Forms.Tools.StyleNamePair("BaseStyle3", treeNodeAdvStyleInfo3)});
 
//To set the BaseStyle for TreeNodeAdv
foreach (TreeNodeAdv tree in this.TreeViewAdv1.Nodes)
{
    tree.BaseStyle = "BaseStyle1";
}
 
for (int i = 0; i < this.TreeViewAdv1.Nodes.Count; i++)
{
    foreach (TreeNodeAdv tree in this.TreeViewAdv1.Nodes[i].Nodes)
    {
        tree.BaseStyle = "BaseStyle2";
    }
}
 
foreach (TreeNodeAdv node in this.TreeViewAdv1.Nodes[0].Nodes[1].Nodes)
{
    node.BaseStyle = "BaseStyle3";
}
this.TreeViewAdv1.Nodes[0].Nodes[1].Nodes[1].Nodes[0].BaseStyle = "BaseStyle2";
this.TreeViewAdv1.Nodes[2].Nodes[1].Nodes[0].BaseStyle = "BaseStyle3";
 

 

VB

'The list of the colors gradient color
Dim Brush1 As New BrushInfoColorArrayList()
Brush1.Add(Color.Yellow)
Brush1.Add(Color.Gray)
 
Dim Brush2 As New BrushInfoColorArrayList()
Brush2.Add(Color.Yellow)
Brush2.Add(Color.Green)
Brush2.Add(Color.LightGray)
 
Dim Brush3 As New BrushInfoColorArrayList()
Brush3.Add(Color.Yellow)
Brush3.Add(Color.Green)
Brush3.Add(Color.LightGray)
 
'To set the Back ground color for TreeNodeAdvStyleInfo'
treeNodeAdvStyleInfo1.Background = New Syncfusion.Drawing.BrushInfo(GradientStyle.PathEllipse, Brush1)
'To set the Text color for TreeNodeAdvStyleInfo
treeNodeAdvStyleInfo1.TextColor = Color.WhiteSmoke
 
treeNodeAdvStyleInfo2.Background = New Syncfusion.Drawing.BrushInfo(GradientStyle.ForwardDiagonal, Brush2)
treeNodeAdvStyleInfo2.TextColor = Color.Yellow
 
treeNodeAdvStyleInfo3.Background = New Syncfusion.Drawing.BrushInfo(GradientStyle.BackwardDiagonal, Brush3)
treeNodeAdvStyleInfo3.TextColor = Color.Brown
 
'To add TreeNodeAdvStyleInfo into TreeViewAdv BaseStyle
Me.TreeViewAdv1.BaseStylePairs.AddRange(New Syncfusion.Windows.Forms.Tools.StyleNamePair() {New Syncfusion.Windows.Forms.Tools.StyleNamePair("BaseStyle1", treeNodeAdvStyleInfo1),
     New Syncfusion.Windows.Forms.Tools.StyleNamePair("BaseStyle2", treeNodeAdvStyleInfo2), New Syncfusion.Windows.Forms.Tools.StyleNamePair("BaseStyle3", treeNodeAdvStyleInfo3)})
 
'To set the BaseStyle for TreeNodeAdv
For Each tree As TreeNodeAdv In Me.TreeViewAdv1.Nodes
    tree.BaseStyle = "BaseStyle1"
Next
For i As Integer = 0 To Me.TreeViewAdv1.Nodes.Count - 1
     For Each tree As TreeNodeAdv In Me.TreeViewAdv1.Nodes(i).Nodes
           tree.BaseStyle = "BaseStyle2"
     Next
Next
 
For Each node As TreeNodeAdv In Me.TreeViewAdv1.Nodes(0).Nodes(1).Nodes
    node.BaseStyle = "BaseStyle3"
Next
 
Me.TreeViewAdv1.Nodes(0).Nodes(1).Nodes(1).Nodes(0).BaseStyle = "BaseStyle2"
Me.TreeViewAdv1.Nodes(2).Nodes(1).Nodes(0).BaseStyle = "BaseStyle3"

 

Applied gradient style to treenode in WinForms Treeview

Figure 1. Gradient style TreeNodeAdv.

Note:

TreeNodeAdvStyleInfo class contains the all the required customization options, such as Background, CheckColor, Font, HelpText, InteractiveCheckBox, IntermediateCheckBoxBackground, IntermediateCheckColor, OptionButtonColor, SelectedOptionButtonColor, Text, TextColor, ThemesEnabled and etc.

Samples:

C#: TreeNodeAdv_GradientStyle_C# sample

VB: TreeNodeAdv_GradientStyle_VB_Sample

Reference link: https://help.syncfusion.com/windowsforms/treeview/appearance#colorcustomization

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied