Get System.Drawing.Font width?

孤街醉人 提交于 2019-12-05 08:30:13

Use Graphics.MeasureString Method (String, Font):

Eg.

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

What width? GetHeight returns the distance between the baselines of two lines of text, which is a property of the font itself. But the width depends on what you're going to write.

If you know what it is you want to write, try the Graphics.MeasureString methods.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!