2012-12-23 5 views
1

Windows Forms에서 C#을 사용하여 DataGridviews를 사용자 정의하고 싶습니다. 내가 뭘 원하는 내가 만든 그라데이션으로 데이터 그리드 헤더를 페인트하는 것입니다Winform C# Datagridview 페인트 머리글

public void Colorear_Barra_abajo(object sender, PaintEventArgs e) 
    { 
     Rectangle r = new Rectangle(0,0, panel_Borde_abajo.Width, panel_Borde_abajo.Height); 

     if (r.Width > 0 && r.Height > 0) 
     { 
      Color c1 = Color.FromArgb(255, 54, 54, 54); 
      Color c2 = Color.FromArgb(255, 62, 62, 62); 
      Color c3 = Color.FromArgb(255, 98, 98, 98); 

      LinearGradientBrush br = new LinearGradientBrush(r, c1, c3, 90, true); 
      ColorBlend cb = new ColorBlend(); 
      cb.Positions = new[] { 0, (float)0.5, 1 }; 
      cb.Colors = new[] { c1, c2 , c3 }; 
      br.InterpolationColors = cb; 

      // paint 
      e.Graphics.FillRectangle(br, r); 
     } 
    } 

문제는 내가 이것을 사용 할수 없어 있도록 datagridviews 페인트 이벤트를하지 않는다는 것입니다. 그래디언트로 머리글을 칠하는 방법이 있습니까? 또는 유일한 방법은 하나의 배경색을 선택하는 것입니다.

감사합니다 ..

답변

6

당신이 Column Header을 의미하는 경우, 예. 에서 CellPainting Event

private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) 
    { 
     if (e.RowIndex == -1) 
     { 
      Color c1 = Color.FromArgb(255, 54, 54, 54); 
      Color c2 = Color.FromArgb(255, 62, 62, 62); 
      Color c3 = Color.FromArgb(255, 98, 98, 98); 

      LinearGradientBrush br = new LinearGradientBrush(e.CellBounds, c1, c3, 90, true); 
      ColorBlend cb = new ColorBlend(); 
      cb.Positions = new[] { 0, (float)0.5, 1 }; 
      cb.Colors = new[] { c1, c2, c3 }; 
      br.InterpolationColors = cb; 


      e.Graphics.FillRectangle(br, e.CellBounds); 
      e.PaintContent(e.ClipBounds); 
      e.Handled = true; 
     } 
    } 
+0

그게 효과가있어! 정말 고마워! – Andres

관련 문제