I have a label on a form that has a fixed pixel width and height. The text for that label could be a small one word response, or it could be several lines. What I want to do is check the length of the response, if needs be split it onto two lines (without cutting off the ends of words, so probably using a regex ' ',',' , ':' or something like that).
I initially tried wrapping the text based on number of characters, which does work. The problem is, even though the following two lines are the same number of characters -
Example 1 - llllllllllllllllllllllllllllll
Example 2 - wwwwwwwwwwwwwwwwwwwwwwwwwwwwww
there is obviously a huge difference in the pixel width. (This is an extreme case but you get my point). The answer is probably TextRenderer.MeasureText but I can't work out how to a) split it without cutting off the ends of words, and b) ensure it goes no further than two lines?
I thought about putting every character into an array and looping through measuring the pixel width, but surely there must be a better way?
Any help would be appreciated!
Thanks in advance