C#中渐变色的代码实例,用于自绘菜单

Graphics g = e.Graphics;
LinearGradientBrush brush = new LinearGradientBrush(this.ClientRectangle,Color.SkyBlue, Color.White, LinearGradientMode.Horizontal);

g.FillRectangle(brush, this.ClientRectangle);//画一个渐变色的块
brush.Dispose();

brush = new LinearGradientBrush(this.ClientRectangle, Color.DarkBlue, Color.White, LinearGradientMode.Horizontal);
g.DrawLine(new Pen(brush, 1), 0, 0, this.Width, 0);//渐变色线
g.DrawLine(new Pen(brush, 1), 0, this.Height-1, this.Width, this.Height-1);
brush.Dispose();
g.Dispose();

其中主要是引入LinearGradientBrush,在文件头部
using System.Drawing.Drawing2D;

【原创 http://www.cnblogs.com/vic_lu/archive/2010/08/24/1807208.html 】

原文地址:https://www.cnblogs.com/vic_lu/p/1807208.html