2017-11-13 1 views
0

기본적으로 열 머리글 색이 변경되었습니다. 지금, 나는 그것을 정렬됩니다 때 Windows Form에 C 번호의 DataGridView에있는 '정렬 문자 모양 아이콘'색상을 변경하려면 :Windows Form C#의 DataGridView에서 '문자 모양 정렬'색상을 변경하는 방법은 무엇입니까?

enter image description here

위의 그림을 참조하십시오. 열은 정렬되지만 아이콘의 색상은 표시가 부적절합니다.

색상을 변경할 수 있는지 알려주세요. 감사!

답변

0

정렬 아이콘의 색상을 변경하는 속성이 없습니다. 이를 변경하는 옵션으로 CellPainting 이벤트를 처리하고 직접 셀을 그릴 수 있습니다. 열 머리글을 그리기

private void dgv1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) 
{ 
    var grid = (DataGridView)sender; 
    var sortIconColor = Color.Red; 
    if (e.RowIndex == -1 && e.ColumnIndex > -1) 
    { 
     using (var b = new SolidBrush(BackColor)) 
     { 
      //Draw Background 
      e.PaintBackground(e.CellBounds, false); 

      //Draw Text 
      TextRenderer.DrawText(e.Graphics, string.Format("{0}", e.FormattedValue), 
       e.CellStyle.Font, e.CellBounds, e.CellStyle.ForeColor, 
       TextFormatFlags.VerticalCenter | TextFormatFlags.Left); 

      //Draw Sort Icon 
      if (grid.SortedColumn?.Index == e.ColumnIndex) 
      { 
       var sortIcon = grid.SortOrder == SortOrder.Ascending ? "▲":"▼"; 
       TextRenderer.DrawText(e.Graphics, sortIcon, 
        e.CellStyle.Font, e.CellBounds, sortIconColor, 
        TextFormatFlags.VerticalCenter | TextFormatFlags.Right); 
      } 

      //Prevent Default Paint 
      e.Handled = true; 
     } 
    } 
} 
+0

당신이 사용할 수있는 유일한 솔루션입니다. 대답은 예제이므로 정렬 아이콘으로 ▲ 및 ▼를 사용했습니다. 'FillPolygon' 또는'FillPath'를 사용하여 간단히 그릴 수 있습니다. 대답을 적용하는 데 문제가 있으면 알려주십시오. –

관련 문제