开发者

C# drawing text

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜