Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12398412
  • 博文数量: 1293
  • 博客积分: 13501
  • 博客等级: 上将
  • 技术积分: 17974
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 18:11
文章分类

全部博文(1293)

文章存档

2019年(1)

2018年(1)

2016年(118)

2015年(257)

2014年(128)

2013年(222)

2012年(229)

2011年(337)

分类: C#/.net

2016-08-11 10:28:31

//先拖一个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);
        }

转自:
阅读(3608) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~