coloured TreeNode

  • Thread starter Thread starter Krzychu
  • Start date Start date
K

Krzychu

Guest
Hi All!
I'm from Poland. I am beginner programmer in Visual Basic .NET.
I want, that all TreeNodes in my treeview control will be underlined. Is someone can help me?
 
Sure! You just need to set the NodeFont property of each node
to a new font that is created with the FontStyle Underlined.

When you add nodes to the treeview, create a new font object
that is based on the TreeView's Font and with FontStyle.Underline
as the new style. Then set this font object to the node's NodeFont
property and add it to the TreeView.

You could also create a recursive subroutine that loops through all
the nodes, after they are added, and underlines them by using the
same method.

In this example, tn is the TreeNode to add to the TreeView (tvw),
and f is the Font object to create from the TreeView's font.

Visual Basic:
Dim tn As New TreeNode() ' The Node to add
Dim f As New Font(tvw.Font, FontStyle.Underline) ' The new font for the node
tn.NodeFont = f ' Set the node's font
tvw.Nodes.Add(tn) ' Add the node
 
Thanks for Your code, but I need a whole area of TreeNode to be
underlined, not only a text (just like in PropertyGrid Control).
 
Well, if you want to make the treeview look like a grid, that isn't
possible without a lot of code (I don't think owner-drawing
TreeView items in VB.NET is possible without the Windows API).

If you want a grid-looking control, try the ListView.
 
Back
Top