DrawString Graphics with Controlled Word Wrap

Basically, my problem is that I need the text to wrap the string whenever I want. Not when .NET wants it. I understand that the DrawString method automatically wraps the word if I give it a rectangle to draw inside. I need to control when this word wraps. So let's say that my line that 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 will have two lines: Testing and 1234. I assume that I need a combination of recalibrating the line (to fit my limitations) and calling the drawstring method to draw each line. The problem is that I really don't know how to do this. I start when it comes to GDI +.

+5
source share
1 answer

You can replace the spaces with newline characters and then draw a line.

string converted = text.Replace(" ", System.Environment.NewLine);
+5
source

All Articles