dev gridControl 自定义绘制列头颜色

1、添加事件CustomDrawColumnHeader
private void gvw1_CustomDrawColumnHeader(object sender, DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventArgs e)
{
  if (e.Column == null || (e.Column.AppearanceHeader.BackColor == Color.Empty && !e.Column.AppearanceHeader.Options.UseBackColor))
    return;
  Rectangle rect = e.Bounds;
  rect.Inflate(-1, -1);
  // 填充标题颜色.
  e.Graphics.FillRectangle(new SolidBrush(e.Column.AppearanceHeader.BackColor), rect);
  e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect);
  // 绘制过滤和排序按钮.
  foreach (DrawElementInfo info in e.Info.InnerElements)
  {
    if (!info.Visible) continue;
    ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo);
  }
  e.Handled = true;
}
2、设置列头颜色
gvw1.Columns["Zxnum"].AppearanceHeader.BackColor = Color.Yellow;
gvw1.Columns["Zxnum"].AppearanceHeader.ForeColor = Color.Black;

posted @ 2018-04-17 12:25  奔跑丶蜗牛  阅读(1353)  评论(0编辑  收藏