PathGradientBrush类进行渐变颜色的填充

 1 private void Form1_Paint(object sender, PaintEventArgs e)
 2 {
 3     Graphics g = e.Graphics;
 4     GraphicsPath gp = new GraphicsPath();
 5 
 6     gp.AddLine(10, 10, 110, 15);
 7     gp.AddLine(110, 15, 110, 96);
 8     gp.AddLine(100, 96, 15, 110);
 9     gp.CloseFigure();
10 
11     g.FillRectangle(Brushes.White,this.ClientRectangle);
12     g.SmoothingMode = SmoothingMode.AntiAlias;   //反锯齿
13  
14    PathGradientBrush pgb = new PathGradientBrush(gp);
15     pgb.CenterColor = Color.White;
16     pgb.SurroundColors = new Color[]
17     {
18          Color.Blue
19      };
20      g.FillPath(pgb,gp);
21      g.DrawPath(Pens.Black,gp);
22      pgb.Dispose();
23      gp.Dispose();
24 }

 GraphicsPath:可以添加自定义的由一系列相互连接的直线、曲线连接起来组成的开放(非闭合)图形。
   创建路径时就会隐式创建一个新图形(由上面的直线、曲线等组成)

posted @ 2016-07-01 09:13  苦力劳动者  阅读(462)  评论(0编辑  收藏  举报