How to measure the pixel width of a digit in a given font / size (C#)

后端 未结 5 1858
闹比i
闹比i 2021-01-04 23:53

I am trying to calculate the pixel width of Excel columns, as described in this post, using the official formula from the OpenXML specification. However, in order to apply t

5条回答
  •  猫巷女王i
    2021-01-05 00:45

    TextRenderer is not always accurate the way you would expect:

    From MSDN: http://msdn.microsoft.com/en-us/library/8wafk2kt.aspx

    For example, the default behavior of the TextRenderer is to add padding to the bounding rectangle of the drawn text to accommodate overhanging glyphs

    Do you have a Graphics object or a Control object? If you are using these you can get accurate restults the way you would expect.

    Take a look at http://msdn.microsoft.com/en-us/library/6xe5hazb(VS.80).aspx

提交回复
热议问题