TreeView... label width

G

Guest

Using VS.NET 2003, VB:
I have a TreeView object with lots of nodes. The treeview is docked on the
left side of my main from in a splitter. I want to set the splitter's initial
width to allow all the treeViews' nodes' labels to be visible.

The algorithm is simple, for each node in the tree view compare node's label
with the max width, and so on. The problem that I've got is how do I discover
the width of a TreeView's label? All I can find is the Text property - and
that doesn't translate well into a pixel width.

Any suggestions?
 
O

Oliver Sturm

Using VS.NET 2003, VB:
I have a TreeView object with lots of nodes. The treeview is docked on the
left side of my main from in a splitter. I want to set the splitter's
initial
width to allow all the treeViews' nodes' labels to be visible.

The algorithm is simple, for each node in the tree view compare node's
label
with the max width, and so on. The problem that I've got is how do I
discover
the width of a TreeView's label? All I can find is the Text property - and
that doesn't translate well into a pixel width.

You'll have to calculate the width yourself, using the
Graphics.MeasureString method. While I was looking for a link to give you,
I found that there's actually an example of this very thing on the MSDN
page about the Control.CreateGraphics method: http://shrinkster.com/87i



Oliver Sturm
 
G

Guest

Thanks for the link...

Oliver Sturm said:
You'll have to calculate the width yourself, using the
Graphics.MeasureString method. While I was looking for a link to give you,
I found that there's actually an example of this very thing on the MSDN
page about the Control.CreateGraphics method: http://shrinkster.com/87i



Oliver Sturm
 
G

Guest

I need to inspect each node in the treeView. But unfortunately the
CreateGraphics() method is available for TreeNode objects. Any other ideas on
how to interrogate the tree node to gets its pixel width?
 
O

Oliver Sturm

I need to inspect each node in the treeView. But unfortunately the
CreateGraphics() method is available for TreeNode objects. Any other ideas
on
how to interrogate the tree node to gets its pixel width?

You should be able to use any other Graphics object for the task. You
could query one from the TreeView control, or even create your own from a
bitmap or other source.



Oliver Sturm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top