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