DrawString, multiline string but full width

S

Sin Jeong-hun

Hello.
It seems like the default behavior of DrawString is trying to keep the
whole word if possible. I'd like the string to be drawn in multilines,
but filling the entire line width.
For example I'm using a fixed-width font, and the width of the layout
rectangle is that of 12 characters, the result I want is,
This is a sa
mple text.
not,
This is a
sample text.

I set the StringFormatFlags.Wrap = false, but it disabled multiline
drawing that wasn't what I wanted.

Is what I'm trying to do achievable with any formatting options or do
I have to draw each character manually with my own calculation?
 
S

Sin Jeong-hun

It seems like the default behavior of DrawString is trying to keep the
whole word if possible. I'd like the string to be drawn in multilines,
but filling the entire line width.
[...]
Is what I'm trying to do achievable with any formatting options or do
I have to draw each character manually with my own calculation?

Off the top of my head, I think maybe you want to set the  
StringFormat.Trimming property to Character.

If I'm mistaken about that, you may be able to use the TextRenderer class  
instead to do your drawing, using the TextFormatFlags.WordBreak flag (or  
rather, making sure that flag is _not_ set) to have the text wrapped on  
whatever character reaches the very end of the line.

Sorry I'm being so vague...I don't have something right in front of me  
that would let me test the code to make sure my recollection is right.

Pete

Thank you for your reply. But, DrawString() with Trimming property set
to Character didn't work. It was the same as when I didn't even set
the Trimming property. Secondly, TextRender.DrawText draws multiline
text if and only if the TextFormatFlag has WordBreak. Setting
WorkBreak gave the same result as when I used DrawString().
 
S

Sin Jeong-hun

It seems like the default behavior of DrawString is trying to keep the
whole word if possible. I'd like the string to be drawn in multilines,
but filling the entire line width.
[...]
Is what I'm trying to do achievable with any formatting options or do
I have to draw each character manually with my own calculation?
Off the top of my head, I think maybe you want to set the  
StringFormat.Trimming property to Character.
If I'm mistaken about that, you may be able to use the TextRenderer class  
instead to do your drawing, using the TextFormatFlags.WordBreak flag (or 
rather, making sure that flag is _not_ set) to have the text wrapped on  
whatever character reaches the very end of the line.
Sorry I'm being so vague...I don't have something right in front of me  
that would let me test the code to make sure my recollection is right.

Thank you for your reply. But, DrawString() with Trimming property set
to Character didn't work. It was the same as when I didn't even set
the Trimming property. Secondly, TextRender.DrawText draws multiline
text if and only if the TextFormatFlag has WordBreak. Setting
WorkBreak gave the same result as when I used DrawString().

Please just let me know if what I'm trying to do cannot be achieved
with some flags. Then I can start writing manual line breaking codes.
Thank you.
 

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