0
gfx.DrawString(
    thisTempLabel.LabelText,
    new Font("Arial", (float)thisTempLabel.fontSize),
    Brushes.Black,
    new PointF(thisTempLabel.x, thisTempLabel.y)
    );

This works fine, except I store my font size (thisTempLabel.fontSize) in pixels. I can't for the life of me work out how to convert them (probably impossible) or what to do to resolve this.

They come out sort of right, but not in the right position by a bit and a bit too big.

Precision is very important.

1 Answer 1

2

I think the issue you're having might be that the constructor you're using expects the size to be in points:

public Font(FontFamily family, float emSize)

emSize
Type: System.Single
The em-size, in points, of the new font.

It looks like you can use a different overload that takes GraphicsUnit parameter, which you can set to GraphicsUnit.Pixel:

gfx.DrawString(
    thisTempLabel.LabelText,
    new Font("Arial", (float)thisTempLabel.fontSize, GraphicsUnit.Pixel),
    Brushes.Black,
    new PointF(thisTempLabel.x, thisTempLabel.y)
);

Note that you're setting the em size, which is, roughly, the height of the "M" character.

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

1 Comment

Thanks! How would I modify my code to use this? I find msdn documentation confusing :S

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.