命名空间:System.Drawing.Drawing2D
LinearGradientBrush对象用颜色线性渐变填充图形。简言之,颜色渐变包含一种在两种指定的颜色之间渐变的颜色,渐变的方向是沿着指定角度的直线路径。例如:
1 private void Form1_Paint(object sender, PaintEventArgs e) 2 { 3 Graphics g = e.Graphics; 4 LinearGradientBrush lgb = new LinearGradientBrush(new Point(0,0), 5 new Point(50,10), 6 Color.White, 7 Color.Black); 8 g.FillRectangle(lgb,this.ClientRectangle); 9 lgb.Dispose(); 10 }
图形为:
使用矩形渐变:
1 private void Form1_Paint(object sender, PaintEventArgs e) 2 { 3 Graphics g = e.Graphics; 4 LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(0,0,50,50), 5 Color.White, 6 Color.Black, 7 75f); //75f 表示角度 8 g.FillRectangle(lgb,this.ClientRectangle); 9 lgb.Dispose(); 10 }