获取System.Drawing.Font宽度是多少? [英] Get System.Drawing.Font width?
本文介绍了获取System.Drawing.Font宽度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用.Net工具做一些2D绘图。 System.Drawing.Font
使用 getHeight()都会
返回像素高度。我失去了一个的getWidth()
检索宽度!我应该使用什么?
I'm using .Net tools to do some 2D drawing. System.Drawing.Font
uses a GetHeight()
that returns the height in pixels. I'm missing a GetWidth()
to retrieve the width! What should I use?
推荐答案
使用的 Graphics.MeasureString方法(String,字体)
Use Graphics.MeasureString Method (String, Font):
例如:
// 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
这篇关于获取System.Drawing.Font宽度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文