//先拖一个label1到界面,然后在Paint事件里面复制代码
private void Form1_Paint(object sender, PaintEventArgs e)
{
Font f = label1.Font;
Graphics g = e.Graphics;
SizeF z = g.MeasureString(label1.Text, f);//关键
//为了验证是否为显示的字符串长度
g.DrawRectangle(new Pen(Color.Red), 0, 0, z.Width, z.Height);
}
转自:
http://zhidao.baidu.com/link?url=2CvDQybhANGwzVbdPA8hX5F0BzBcPf41NNOVBb5I_tuxgV9e5r3-Vn6sl7oPw6VjevYT99Tm3yYwDcMF1kh8y8aPCjspWmqgWCn1txcTGYO