第一步:设置界面
在窗体中设置三个radioButton组件,改变属性为各自颜色(红绿蓝)
添加一个panel1组件,用以显示多边形
可以添加一个lable组件,用以指示功能,文本设置为"选择绘制图形的颜色:"
第二步:设置属性
第三步:写代码
//红色多边形
private void radioButton1_Click(object sender, EventArgs e)
{
Pen p1=new.Pen(Color.Red, 5);//创建笔
Graphics g1= panel1.CreateGraphics(); //创建画板
Brash a=new SolidBrush(Color.Red);//创建实体笔刷
//创建点
Point p1=new Point(0,76);
Point p2= new Point(80,76);
Point p3=new Point (106,0);
Point p4=new Point (130,76);
Point p5= new Point (210,76);
Point p6= new Point ((146,124);
Point p7= new Point (170,200);
Point p8=new Point (106,152);
Point p9=new Point (40,200);
Point p10=new Point (66, 124);
Point[]myPoints={p1,p2,p3,p4,p5,p6,p7,p8,p9,p10}
g.DrawPolygon(pen, myPoint);//用笔pen绘制多边
g1.FillPolgon(a,DrawPolgon);//填充多边形
//绿色多边形
private void radioButton2_Click(object sender, EventArgs e)
{
Pen p1=new.Pen(Color.Green, 5);
Graphics g1= panel1.CreateGraphics();
Brash a=new SolidBrush(Color.Green);
Point p1=new Point(0,76);
Point p2= new Point(80,76);
Point p3=new Point (106,0);
Point p4=new Point (130,76);
Point p5= new Point (210,76);
Point p6= new Point ((146,124);
Point p7= new Point (170,200);
Point p8=new Point (106,152);
Point p9=new Point (40,200);
Point p10=new Point (66, 124);
Point[]myPoints={p1,p2,p3,p4,p5,p6,p7,p8,p9,p10}
g.DrawPolygon(pen, myPoint);
g1.FillPolgon(a,myPoints);
//蓝色多边形
private void radioButton2_Click(object sender, EventArgs e)
{
Pen p1=new.Pen(Color.Blue, 5);
Graphics g1= panel1.CreateGraphics();
Brash a=new SolidBrush(Color.Blue);
Point p1=new Point(0,76);
Point p2= new Point(80,76);
Point p3=new Point (106,0);
Point p4=new Point (130,76);
Point p5= new Point (210,76);
Point p6= new Point ((146,124);
Point p7= new Point (170,200);
Point p8=new Point (106,152);
Point p9=new Point (40,200);
Point p10=new Point (66, 124);
Point[]myPoints={p1,p2,p3,p4,p5,p6,p7,p8,p9,p10}
g.DrawPolygon(pen, myPoint);
g1.FillPolgon(a,myPoints);
}}}