因为用到了椭圆及渐变效果,所以需引用以下的命名空间:

     using System.Drawing;
     using System.Drawing.Drawing2D;

 

代码实现技术如下:

       private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Brush brGradient = new LinearGradientBrush(new Rectangle(0,0,400,400),Color.Black,Color.Red,45,false);
            Brush brHatch = new HatchBrush(HatchStyle.HorizontalBrick, Color.Black, Color.Yellow);
            Brush brsolid = new SolidBrush(Color.SlateBlue);
         
            g.FillRectangle(brGradient,10,10,200,180);   //画正方形
            g.FillEllipse(brHatch,150,200,150,190);      //椭圆
            g.FillPie(brsolid,80,0,300,300,285,75);    //扇形
        }

实现效果图:

        

自动绘制相关图形及实现渐变颜色_职场