m q

m q

  • NA
  • 5
  • 0

Adjust control size to dynamically changing text; wordwrapped text

Feb 5 2009 11:12 AM
Hello.  First of all, I am using C# Compact Framework 2.X.  Now, I have a label control, and its text is set dynamically, so I don't know what size to set it.  If only I could measure how much space was needed for the text, I could manually move all of the controls around it and manually set the label's size.

Now, I know about the Graphics.measureString() method.  This only measures a string horizontally, not vertically (i.e. word wraps make the text go to the next lines; I need to know how many vertical lines of text there are).

Also, I tried measuring the entire string width as if it were on one line, and dividing that by the width of the label to see how many lines of text there are.  This doesn't work when you have odd strings such as strings with really long words or newlines.

So, is there a way to measure how many lines are needed when you word wrap to a specific width?

Thanks!

Answers (5)