needed lines for Text-expression, word wrapping

  • Thread starter Thread starter c_xyTopa
  • Start date Start date
C

c_xyTopa

hi all,

a have a Label-Text with x-Words. I need to count how many lines are
needed in order to set the Label.Height (Label.Width maxLabelWidth is
constant).

I count the words, count their size with blanks between them

SizeF szF = g.MeasureString(currentWord, this.label1.Font);
sum += sz.ToSize().Width;

in the end I count lines needed

neededLinesCounter = sum / maxLabelWidth;
if (sum % maxLabelWidth > 0)
neededLinesCounter++;



the problem:
if the size of all words is 500 and maxLabelWidth = 160 I get 4 lines
and the whole expression fixes fine.

if the size of all words is 500 and maxLabelWidth = 120 I get 5 lines
and the whole expression does not fix.

I suppose it's while the words wrapping is not available.
How could I solve the problem?

thanx
 
Back
Top