//重写OnPaint方法后,添加以下代码,注释部分可以放开!同时要注释点相应画刷
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;//画布
//画笔
Pen redPen = new Pen(Color.Red, 2);
Pen greenPen = new Pen(Color.Green, 2);
Pen bluePen = new Pen(Color.Blue, 2);
Pen magentaPen = new Pen(Color.Magenta, 4);
Pen fuchsiaPen = new Pen(Color.Fuchsia, 8);
Pen hotpinkPen = new Pen(Color.HotPink, 12);
//画刷
Brush yellowbrush = new HatchBrush(HatchStyle.Percent90, Color.Yellow);
Brush alicebluebrush = new HatchBrush(HatchStyle.Percent10, Color.AliceBlue);
Brush beigebrush = new HatchBrush(HatchStyle.Percent20, Color.Beige);
Brush Burlywoodbrush = new HatchBrush(HatchStyle.Percent25, Color.BurlyWood);
Brush lemonchiffonbrush = new HatchBrush(HatchStyle.Percent30, Color.LemonChiffon);
Brush rosybrownbrush = new HatchBrush(HatchStyle.Percent40, Color.RosyBrown);
//画刷
//Brush yellowbrush = new SolidBrush(Color.Yellow);
//Brush alicebluebrush = new SolidBrush(Color.AliceBlue);
//Brush beigebrush = new SolidBrush(Color.Beige);
//Brush Burlywoodbrush = new SolidBrush(Color.BurlyWood);
//Brush lemonchiffonbrush = new SolidBrush(Color.LemonChiffon);
//Brush rosybrownbrush = new SolidBrush(Color.RosyBrown);
//画出各种图形
g.DrawArc(magentaPen, 10, 10, 100, 100, 0, -270);
g.DrawEllipse(hotpinkPen, 150, 10, 100, 200);
g.DrawEllipse(bluePen, 300, 10, 100, 100);
g.DrawLine(fuchsiaPen, 450, 20, 700, 60);
g.DrawLine(fuchsiaPen, 500, 60, 700, 20);
g.DrawPie(redPen, 20, 300, 200, 200, 0, -135);
//坐标
Point[] mypt1 = new Point[3];
mypt1[0].X = 10;
mypt1[0].Y = 120;
mypt1[1].X = 10;
mypt1[1].Y = 170;
mypt1[2].X = 100;
mypt1[2].Y = 200;
g.DrawPolygon(greenPen, mypt1);
g.DrawRectangle(bluePen, 300, 150, 150, 200);
Font ArialFont = new Font("Arial", 18);
string header = "Drawing a string of text";
g.DrawString(header, ArialFont, rosybrownbrush, 20, 250);
g.FillEllipse(Burlywoodbrush, 500, 150, 150, 200);
g.FillPie(alicebluebrush, 20, 500, 200, 200, -45, -90);
Point[] mypt2 = new Point[5];
mypt2[0].X = 450;
mypt2[0].Y = 500;
mypt2[1].X = 500;
mypt2[1].Y = 550;
mypt2[2].X = 550;
mypt2[2].Y = 525;
mypt2[3].X = 550;
mypt2[3].Y = 475;
mypt2[4].X = 500;
mypt2[4].Y = 450;
g.FillPolygon(beigebrush, mypt2);
g.FillRectangle(lemonchiffonbrush, 250, 400, 150, 150);
redPen.Dispose();
greenPen.Dispose();
bluePen.Dispose();
magentaPen.Dispose();
fuchsiaPen.Dispose();
hotpinkPen.Dispose();
yellowbrush.Dispose();
alicebluebrush.Dispose();
beigebrush.Dispose();
Burlywoodbrush.Dispose();
lemonchiffonbrush.Dispose();
rosybrownbrush.Dispose();
}