Live Chat Icon For mobile
Live Chat Icon

MeasureString seems to have problems with white space and punctuation. Is there a better method to use

Platform: WinForms| Category: Fonts

Try calling one of the overloads of MeasureString that takes an StringFormat parameter and pass it StringFormat.GenericTypographic. Here is some code that shows the same string and font giving different results depending upon the StringFormat parameter.

StringFormat sf = new  StringFormat(StringFormat.GenericTypographic);

SizeF size =  e.Graphics.MeasureString('this has some words', Font, 500, sf);
SizeF size1 = e.Graphics.MeasureString('this has some words', Font);
string s = string.Format('GenericTypographic={0:f2}   GenericDefault={1:f2}', size.Width, size1.Width);
MessageBox.Show(s);

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.