找了半天没有找到,貌似只能设置背景颜色?是在不行设置为渐进色也行啊。
谢谢了。

解决方案 »

  1.   

    //行头,列头背景颜色渐变  
     protected override void OnCellPainting(System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
           {
               Color mLinearColor1 = Color.FromArgb(51, 122, 167);
               Color mLinearColor2 = Color.FromArgb(255, 255, 255);
               Color mGridColor = Color.FromArgb(120, 147, 191);  //网格线的颜色           Rectangle Rect = new Rectangle(e.CellBounds.X - 1, e.CellBounds.Y, e.CellBounds.Width, e.CellBounds.Height - 1);
               LinearGradientBrush LinearGradientBrushs = new LinearGradientBrush(Rect, mLinearColor1, mLinearColor2, LinearGradientMode.Vertical);
               
               try
               {
                       if (e.RowIndex == -1 || e.ColumnIndex == -1)
                       {
                           e.Graphics.FillRectangle(LinearGradientBrushs, Rect);
                           e.Graphics.DrawRectangle(new Pen(mGridColor), Rect);
                           e.PaintContent(e.CellBounds);
                           e.Handled = true;
                       }
               }           catch
               { }
               finally
               {
                   if (LinearGradientBrushs != null)
                   {
                       LinearGradientBrushs.Dispose();
                   }           }           base.OnCellPainting(e);
           }