)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to apply gradient style to TreeNodeAdv in WinForms TreeViewAdv?

Platform: WinForms |
Control: TreeViewAdv |
Published Date: February 15, 2016 |
Last Revised Date: February 4, 2020

Gradient style

The appearance of TreeNodeAdv 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

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon