开发者

Graphics in C# (.NET)

I use this code for drawing text in a panel:

Graphics g = panel1.CreateGraphics();
g.DrawString(...);

So I want to know 开发者_如何转开发what size the input text will be when rendered in the panel.


Use g.MeasureString() to get the width of a string in the grapic context.

// 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);


You can also use TextRenderer.MeasureText which is sometimes easier to use than MeasureString.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜