TreeView node.Bounds.Width and DrawString

T

timtos

I am working on a custom treeView and have some problems with
a) node.Bounds.Width
b) concatenate strings drawn with DrawString(...)

a)
I want to highlight a selected node and used the node.Bounds dimensions
to draw a rectangle around the node but the node.Bounds.Width property
seems to be wrong. Sometimes the rectangle is too large and sometimes
it is too small; something like this

selectedNo(*)de
selectedNodeselect(*)edNode
selNod(*)e

(*) = the end of the rectangle - although the node.Bounds dimensions are used.
What can that be?

b)
I want to concatenate two strings drawn with DrawString.
How do I get the exact width of such a drawn string?
Or in other words - How do I get to know where to let the second string start?
I´ve tried something like this:

int width = this.node.Font.Size * text1.Length;

But of course that isn´t working...


Any ideas about these two topics?
Thanks really a lot for any hints!

Greetings,
timtos.
 
C

Chris Taylor

Hi,

I have not looked at the node bounds. But on the point of the DrawString,
firstly why don't you concactenate the strings into a new string then draw
that string with one DrawString? Assuming you have good reason not to do
this, take a look at MeasureString it should help you.

Hope This Helps

Chris Taylor
 

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