needed lines for Text-expression, word wrapping

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top