protected override void OnPaint(PaintEventArgs e)

{

base.Onpaint(e);

//定义画布

Graphics g=e.Graphics;

//定义一个矩形(当前窗体)

Rectangle rec=new Rectangle (0,0,this.Width,this.Height);

//定义一个带渐变色的画刷,LinearGradientMode为渐变色的填充方式

LinearGradientBrush brush=new LinearGradientBrush(rec,Color.FromArgb(220,100,200),Color.FromArgb(90,120,125),LinearGradientMode.Vertical);

//填充矩形

g.FillRectangle(brush,rec);

}