Create a string of n pixel width...  
Author Message
Wex





PostPosted: Sun Nov 27 00:51:05 CST 2005 Top

Visual C#.Net >> 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

DotNet243  
 
 
Reuben





PostPosted: Sun Nov 27 00:51:05 CST 2005 Top

Visual C#.Net >> Create a string of n pixel width... 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.
 
 
Benny





PostPosted: Mon Nov 28 11:04:34 CST 2005 Top

Visual C#.Net >> Create a string of n pixel width... 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.