我正在创建一个自定义控件,其中部分内容使用Graphics
类将文本绘制到窗体上。目前,我正在使用以下代码来显示它:
private float _lineHeight { get { return this.Font.Size + 5; } }
private void Control_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
Brush b = new SolidBrush(Colors[7]);
g.DrawString("Hello World!", this.Font, b, 0, 2);
g.DrawString("This has been a test of the emergency drawing system!",
this.Font, b, 0, 2 + _lineHeight);
}
我目前使用的是固定宽度字体,我想知道字体显示的宽度是多少,但似乎没有相关属性提供这样的信息。有没有什么方法可以获取?我希望能够正确地换行。