码迷,mamicode.com
首页 > 其他好文 > 详细

为动态生成的每一个label添加边框

时间:2016-07-13 13:56:41      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

for (int j = 0; j < name.Count; j++)
{  

  Label lb = new Label();

lb.Paint+=new PaintEventHandler(lb_Paint);

}

///绘画事件

private void lb_Paint(object sender, PaintEventArgs e)
{
Label lb = sender as Label;
DrawRoundRect(e.Graphics, lb);
}

 

///画出边框
private void DrawRoundRect(Graphics graphics, Label label)
{
float X = float.Parse(label.Width.ToString()) - 1;
float Y = float.Parse(label.Height.ToString()) - 1;
PointF[] points = { new PointF(2,0),

          new PointF(X-2,0),

          new PointF(X-1,1),

          new PointF(X,2),

          new PointF(X,Y-2),

          new PointF(X-1,Y-1),

          new PointF(X-2,Y),

          new PointF(2,Y),

          new PointF(1,Y-1),

          new PointF(0,Y-2),

          new PointF(0,2),

          new PointF(1,1)};

GraphicsPath path = new GraphicsPath();
path.AddLines(points);
Pen pen = new Pen(Color.FromArgb(150, Color.Black), 1);

pen.width=5   //画笔的宽度,即边框的宽度
pen.DashStyle = DashStyle.Solid;
graphics.DrawPath(pen, path);
}

为动态生成的每一个label添加边框

标签:

原文地址:http://www.cnblogs.com/vichin/p/5666560.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!