By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

Create a string of n pixel width...

P: n/a
Since I have no control over a treeview's scroll bars (i'm drawing icons
and text to the right of the treenodes) I've decided to just add some
special text to the end of my tree node text which I will then strip out
when it comes to drawing the treenode into the treeview...

Anyway I know there is a way to get the pixel length of a string that
already exists, but is there a good way to create a string of characters
that are a certain length? Should I just have a function that loops
adding 'x' until it's a certain length? Since this will only be run
when a node is created or when a node's special properties change I'm
just planning on doing this - unless any of you know of a better solution.

Thanks,
Benny
Nov 27 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Some methods used for graphics/drawing automatically wrap text a new line
when given the bounds of the Text as a rectangle. I don't know if this is in
CLI but it is in the managed DirectX libraries, so you should be able to do
this somehow. By the way, you'll need a method to tell you the length of the
String with a specified Font- unless you're using a fixed-width font,
different characters will have different (visual) lengths.
Nov 27 '05 #2

P: n/a
Graphics.MeasureString( string text, Font font )

does the measuring of the string automatically for me... What I wanted
was to create a string that was x length automatically... What I ended
up doing was to loop adding a character to my string until MeasureString
returned a value >= the value I wanted. This seems to be working fine.

~Benny

--- Message from Reuben
Some methods used for graphics/drawing
automatically wrap text a new line
when given the bounds of the Text as a
rectangle. I don't know if this is in
CLI but it is in the managed DirectX
libraries, so you should be able to do
this somehow. By the way, you'll need a
method to tell you the length of the
String with a specified Font- unless
you're using a fixed-width font,
different characters will have different
(visual) lengths.

Nov 28 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.