views:

598

answers:

1

Basically my issue is that I need to word wrap a string when I want to. Not when .NET wants to. I understand that the DrawString method will automatically word wrap if I give it a rectangle to draw within. I need to control when it does word wrap it. So lets say my string I want to draw is Testing 1234. And I want to draw text on a new line whenever I see a space. So in this case it would have two lines - Testing and 1234. I am guessing I need a combination of re-sizing the string (to fit my bounds) and multiple drawstring method calls to draw each line. The problem is that I don't really know how to do this. I am a novice when it comes to GDI+.

+4  A: 

You could replace the spaces with newlines and then draw the string.

string converted = text.Replace(" ", System.Environment.NewLine);
Zach Johnson
Yea I didn't think this would work with the MeasureString() method. I assumed that would think it is still a 1 line string and measure it that way. Thanks.
Travyguy9