//先拖一个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);
}
转自:
阅读(3680) | 评论(0) | 转发(0) |