private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.Clear(Color.White);
//定义渐变颜色数组
Color[] colors =
{
Color.Red,
Color.Green,
Color.Blue
};
float[] positions =
{
0.0f,
0.3f,
1.0f
};
//定义ColorBlend对象
ColorBlend colorBlend = new ColorBlend(3);
colorBlend.Colors = colors;
colorBlend.Positions = positions;
//定义线型渐变画刷
using (LinearGradientBrush lBrush = new LinearGradientBrush(ClientRectangle, Color.White, Color.Black, LinearGradientMode.Horizontal))
{
//设置渐变画刷的多色渐变信息
lBrush.InterpolationColors = colorBlend;
g.FillRectangle(lBrush, ClientRectangle);
}
}
效果图: