学习GDI+ 随便画着玩,研究中c#(winform)

//重写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();

        }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值