问一下datagridview列标题是那个属性,我只是想把列标题的颜色换得漂亮点 

解决方案 »

  1.   

    datagridview.ColumnHeadersBorderStyle
    设置标题列的样式颜色。。
      

  2.   


    //设置为Blue
    datagridview1.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue;
      

  3.   

    //设置渐变的行,列头 
    protected override void OnCellPainting(System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
           {
               //string strSkinName = (new ApplicationConfiguration()).GetStringValue("ColorName");
               Color mLinearColor1 = Color.FromArgb(51, 122, 167);
               //Color mLinearColor1 = Color.FromArgb(int.Parse((new DesEncrypt()).Decode(strSkinName)));
               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);
           }
      

  4.   

    我明白了,让系统属性,高级里面,性能设置为 让WINDOWS 选择计算机最佳设置,是永远无法设置颜色的,除非是调节到最佳性能才可以调出颜色.