[英]How to change 'sort glyph icon' color in DataGridView of Windows Form C#?
沒有用於更改排序圖標顏色的屬性。 作為更改它的選項,您可以處理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 Default
//e.Paint(e.CellBounds, DataGridViewPaintParts.ContentForeground);
//Draw Text Custom
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 ? "▲":"▼";
//Or draw an icon here.
TextRenderer.DrawText(e.Graphics, sortIcon,
e.CellStyle.Font, e.CellBounds, sortIconColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
//Prevent Default Paint
e.Handled = true;
}
}
}
繪制視覺樣式排序圖標
要查看使用Visual Styles排序圖標的繪圖,請查看此文章 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.