MeasureString() pads the text on the left and the right

后端 未结 5 829
野趣味
野趣味 2021-01-04 01:54

I\'m using GDI+ in C++. (This issue might exist in C# too).

I notice that whenever I call Graphics::MeasureString() or Graphics::DrawString(), the string is padded

5条回答
  •  盖世英雄少女心
    2021-01-04 02:28

    It's true that is by design, however the link on the accepted answer is actually not perfect. The issue is the use of floats in all those methods when what you really want to be using is pixels (ints).

    The TextRenderer class is meant for this purpose and works with the true sizes. See this link from msdn for a walkthrough of using this.

提交回复
热议问题