日期:2014-05-19  浏览次数:20804 次

怎样取得一个字符串的像素宽和像素高
如题,怎样才能准确的取得??

------解决方案--------------------
Fontfamily类
------解决方案--------------------
button1.Font.GetHeight();
------解决方案--------------------
public void MeasureStringMin(PaintEventArgs e)
{

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

// Draw rectangle representing size of string.
e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 0.0F, 0.0F, stringSize.Width, stringSize.Height);

// Draw string to screen.
e.Graphics.DrawString(measureString, stringFont, Brushes.Black, new PointF(0, 0));
}

MSDN上的例子