1

I was wondering what was causing the following issue: If I create a new font, of a specified size in points, then measure a string - in points again, I get two different values?

i.e.

        Font font = new Font("Arial", 36, GraphicsUnit.Point);

        Graphics g =  CreateGraphics();

        g.PageUnit = GraphicsUnit.Point;

        string str = "hello";

        SizeF size = g.MeasureString(str, font);

size.height == 44 as opposed to 36 which is the specified PT size of the font!!

Whats going on??!!!

2 Answers 2

1

MeasureString pads the returned rect to allow for overhanging and underhanging characters. This shows a typical rect returned by MeasureString:

enter image description here

So naturally the returned height will be larger than the specified size of the font in points.

Sign up to request clarification or add additional context in comments.

1 Comment

@iraSenthil: then why am I still at 0 here? :)
0

Take a look at this link. Extra space might be the reason for different sizes

The MeasureString method is designed for use with individual strings and includes a small amount of extra space before and after the string to allow for overhanging glyphs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.