gpt4 book ai didi

c# - 获取 System.Drawing.Font 宽度?

转载 作者:太空狗 更新时间:2023-10-29 22:16:35 31 4
gpt4 key购买 nike

我正在使用 .Net 工具进行一些 2D 绘图。 System.Drawing.Font 使用 GetHeight() 返回以像素为单位的高度。我缺少 GetWidth() 来检索宽度!我应该使用什么?

最佳答案

使用 Graphics.MeasureString Method (String, Font) :

例如。

   // Set up string. string measureString = "Measure String";
Font stringFont = new Font("Arial", 16);
// Measure string.
SizeF stringSize = new SizeF();
Graphics gfx = Graphics.FromImage(new Bitmap(1, 1));
stringSize = gfx.MeasureString(measureString, stringFont);
// This will give you string width, from which you can calculate further
double width = stringSize.Width

关于c# - 获取 System.Drawing.Font 宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13269145/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com