Jump to content
Xtreme .Net Talk

coloured TreeNode


Recommended Posts

Guest Krzychu
Posted

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?

  • *Experts*
Posted

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.

 

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

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Guest Krzychu
Posted

Thanks for Your code, but I need a whole area of TreeNode to be

underlined, not only a text (just like in PropertyGrid Control).

  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...