private void button1_Click(object sender, EventArgs e)
{
Point [] pt = new Point[10];
pt[0] = new Point(120,46);
pt[1] = new Point(156, 46);
pt[2] = new Point(168, 10);
pt[3] = new Point(180, 46);
pt[4] = new Point(214, 46);
pt[5] = new Point(188, 70);
pt[6] = new Point(198, 106);
pt[7] = new Point(168, 82);
pt[8] = new Point(138, 104);
pt[9] = new Point(150, 70);
GraphicsPath path = new GraphicsPath();
for(int i = 0; i < pt.Length-1; i++)
{
path.AddLine(pt[i], pt[i + 1]);//用线段进行连接
}
path.CloseFigure();//闭合当前图形开始新的图形
Graphics g = CreateGraphics();
g.FillPath(new SolidBrush(Color.Red), path);//Brush brush =new SolidBrush(Color.Red);
//FillPath 是一个路径形式
g.Dispose();
path.Dispose();
}
个人理解 创建10个点,他们的坐标分别是 (120,46)、~~~、(150,70)
定义一个绘画路径的对象 path (相当于 pen)
依次以直线连接这些点
OnPoint() 方法 当窗体加载时就可以绘图!