Articles in this section
Category / Section

How to seperate background between two adjacent nodes in WinForms TreeViewAdv?

2 mins read

You can separate the background between two adjacent nodes in WinForms TreeViewAdv control by using BeforeNodePaint event. Refer the below code for your reference.

C#

treeViewAdv1.BeforeNodePaint += TreeViewAdv1_BeforeNodePaint1;
 
//Customize Background of Nodes
private void TreeViewAdv1_BeforeNodePaint1(object sender, TreeNodeAdvPaintEventArgs e)
{
  LinearGradientBrush lBrush = new LinearGradientBrush(e.Node.Bounds, Color.LightGreen, Color.LightSeaGreen, LinearGradientMode.Horizontal);
  e.Graphics.FillRectangle(lBrush, e.Node.Bounds);
  e.Graphics.DrawRectangle(new Pen(Color.Red), e.Node.Bounds);
}

VB

AddHandler treeViewAdv1.BeforeNodePaint, AddressOf TreeViewAdv1_BeforeNodePaint1
 
'Customize Background of Nodes
Private Sub TreeViewAdv1_BeforeNodePaint1(ByVal sender As Object, ByVal e As TreeNodeAdvPaintEventArgs)
 Dim lBrush As New LinearGradientBrush(e.Node.Bounds, Color.LightGreen, Color.LightSeaGreen, LinearGradientMode.Horizontal)
 e.Graphics.FillRectangle(lBrush, e.Node.Bounds)
 e.Graphics.DrawRectangle(New Pen(Color.Red), e.Node.Bounds)
End Sub

Output:

Customize the background of WF TreeViewAdv control

Sample: View sample in GitHub.

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