winform重绘窗体成圆角(网上借鉴)

winform做圆角窗体:

 1 //重绘窗体为圆角
 2         private void frmMain_Paint(object sender, PaintEventArgs e)
 3         {
 4             #region
 5 
 6             List<Point> list = new List<Point>();
 7             int width = this.Width;
 8             int height = this.Height;
 9 
10             #region 四个圆角
11 
12             //左上  
13             list.Add(new Point(0, 5));
14             list.Add(new Point(1, 5));
15             list.Add(new Point(1, 3));
16             list.Add(new Point(2, 3));
17             list.Add(new Point(2, 2));
18             list.Add(new Point(3, 2));
19             list.Add(new Point(3, 1));
20             list.Add(new Point(5, 1));
21             list.Add(new Point(5, 0));
22 
23             //右上  
24             list.Add(new Point(width - 5, 0));
25             list.Add(new Point(width - 5, 1));
26             list.Add(new Point(width - 3, 1));
27             list.Add(new Point(width - 3, 2));
28             list.Add(new Point(width - 2, 2));
29             list.Add(new Point(width - 2, 3));
30             list.Add(new Point(width - 1, 3));
31             list.Add(new Point(width - 1, 5));
32             list.Add(new Point(width - 0, 5));
33 
34             //右下  
35             list.Add(new Point(width - 0, height - 5));
36             list.Add(new Point(width - 1, height - 5));
37             list.Add(new Point(width - 1, height - 3));
38             list.Add(new Point(width - 2, height - 3));
39             list.Add(new Point(width - 2, height - 2));
40             list.Add(new Point(width - 3, height - 2));
41             list.Add(new Point(width - 3, height - 1));
42             list.Add(new Point(width - 5, height - 1));
43             list.Add(new Point(width - 5, height - 0));
44 
45             //左下  
46             list.Add(new Point(5, height - 0));
47             list.Add(new Point(5, height - 1));
48             list.Add(new Point(3, height - 1));
49             list.Add(new Point(3, height - 2));
50             list.Add(new Point(2, height - 2));
51             list.Add(new Point(2, height - 3));
52             list.Add(new Point(1, height - 3));
53             list.Add(new Point(1, height - 5));
54             list.Add(new Point(0, height - 5));
55             #endregion
56 
57             Point[] points = list.ToArray();
58 
59             GraphicsPath shape = new GraphicsPath();
60 
61             shape.AddPolygon(points);
62 
63             this.Region = new System.Drawing.Region(shape);
64             #endregion
65         }

 

posted @ 2015-05-01 11:05  zhaizhuang  阅读(700)  评论(0编辑  收藏  举报