可以用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 }
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 }
图形为: