471,618 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,618 software developers and data experts.

Create a string of n pixel width...

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
2 2353
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
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.

Similar topics

7 posts views Thread by TomHL | last post: by
3 posts views Thread by Sangeeta | last post: by
5 posts views Thread by Lance | last post: by
11 posts views Thread by cc | last post: by
3 posts views Thread by Bart Van der Donck | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.