C#每天抄一点(9):T型窗口
11 Oct 2011这几天一直在写关于窗口的小程序,没办法, 掌握多一些方法以绝后患。
今天这个是利用数组定点实现不规则形状窗口。
关于AddPolygon
GraphicsPath.AddPolygon 方法 (PointF[])
向此路径添加多边形。
命名空间: System.Drawing.Drawing2D
程序集: System.Drawing(在 system.drawing.dll 中)
一个 PointF 结构的数组,它定义要添加的多边形。
points 数组中的点指定多边形的顶点。如果数组中的第一个点与最后一个点不是同一点,则将连接这两个点以闭合多边形。
01 /*
02 * Created by SharpDevelop.
03 * User: Lazynight
04 * Date: 2011/10/11
05 * Time: 18:35
06 *
07 * To change this template use Tools | Options | Coding | Edit Standard Headers.
08 */
09 using System;
10 using System.Collections.Generic;
11 using System.Drawing;
12 using System.Windows.Forms;
13 using System.Drawing.Drawing2D;
14
15 namespace Lazy9_T型窗口
16 {
17 public partial class MainForm : Form
18 {
19 public MainForm()
20 {
21 InitializeComponent();
22 }
23
24 void MainFormLoad(object sender, EventArgs e)
25 {
26 this.Left=(SystemInformation.PrimaryMonitorMaximizedWindowSize.Width-this.Width)/2;
27 this.Top=(SystemInformation.PrimaryMonitorMaximizedWindowSize.Height-this.Height)/2;//初始化窗口位置居中
28 }
29
30 void Button1Click(object sender, EventArgs e)
31 {
32 GraphicsPath Lazy_Form1=new GraphicsPath();//实例化GraphicsPath
33 Point[] Lazy_array= //定义点数组
34 {
35 new Point(,),
36 new Point(this.Width,),
37 new Point(this.Width,this.Height/2),
38 new Point(this.Width-(this.Width/3),this.Height/2),
39 new Point(this.Width-(this.Width/3),this.Height),
40 new Point(this.Width/3,this.Height),
41 new Point(this.Width/3,this.Height/2),
42 new Point(,this.Height/2),
43 };
44 Lazy_Form1.AddPolygon(Lazy_array); //利用数组绘制T型窗口
45 this.Region=new Region(Lazy_Form1);
46 }
47
48 }
49 }
02 * Created by SharpDevelop.
03 * User: Lazynight
04 * Date: 2011/10/11
05 * Time: 18:35
06 *
07 * To change this template use Tools | Options | Coding | Edit Standard Headers.
08 */
09 using System;
10 using System.Collections.Generic;
11 using System.Drawing;
12 using System.Windows.Forms;
13 using System.Drawing.Drawing2D;
14
15 namespace Lazy9_T型窗口
16 {
17 public partial class MainForm : Form
18 {
19 public MainForm()
20 {
21 InitializeComponent();
22 }
23
24 void MainFormLoad(object sender, EventArgs e)
25 {
26 this.Left=(SystemInformation.PrimaryMonitorMaximizedWindowSize.Width-this.Width)/2;
27 this.Top=(SystemInformation.PrimaryMonitorMaximizedWindowSize.Height-this.Height)/2;//初始化窗口位置居中
28 }
29
30 void Button1Click(object sender, EventArgs e)
31 {
32 GraphicsPath Lazy_Form1=new GraphicsPath();//实例化GraphicsPath
33 Point[] Lazy_array= //定义点数组
34 {
35 new Point(,),
36 new Point(this.Width,),
37 new Point(this.Width,this.Height/2),
38 new Point(this.Width-(this.Width/3),this.Height/2),
39 new Point(this.Width-(this.Width/3),this.Height),
40 new Point(this.Width/3,this.Height),
41 new Point(this.Width/3,this.Height/2),
42 new Point(,this.Height/2),
43 };
44 Lazy_Form1.AddPolygon(Lazy_array); //利用数组绘制T型窗口
45 this.Region=new Region(Lazy_Form1);
46 }
47
48 }
49 }
转载请注明:于哲的博客 » C#每天抄一点(9):T型窗口