Graphics.MeasureString

  • Thread starter Thread starter Dom
  • Start date Start date
D

Dom

I have a user control and I do the following:

Graphics g = this.CreateGraphics();
SizeF s = g.MeasureString (MyText, MyFont);

This works fine as long as MyText is not a string of blanks. If it
is, then I always get the same s.Width values. It doesn't matter if
the string is 1 blank or 5 blanks. It doesn't even matter what the
font is. It is always the same.

Any reason?
 
I have a user control and I do the following:

Graphics g = this.CreateGraphics();
SizeF s = g.MeasureString (MyText, MyFont);

This works fine as long as MyText is not a string of blanks. If it
is, then I always get the same s.Width values. It doesn't matter if
the string is 1 blank or 5 blanks. It doesn't even matter what the
font is. It is always the same.

Any reason?

use the overload that takes a stringformat. The intellisense will
explain all :)

new StringFormat(StringFormatFlags.MeasureTrailingSpaces)
 
use the overload that takes a stringformat. The intellisense will
explain all :)

new StringFormat(StringFormatFlags.MeasureTrailingSpaces)

Thanks. Worked like a charm!!

Dom
 
Back
Top