笔者在开发一个MES系统看板模块时采用的是Devexpress GridControl (10.1版 ) 的控件,希望使用GridControl的Header的背景颜色和内容的一致在网上查找了一下使用如下一段代码
public static void CustomDrawColumnHeader(GridControl gridControl, GridView gridView) {
// Handle this event to paint columns headers manually
gridView.CustomDrawColumnHeader += (s, e) => {
if (e.Column == null || e.Column.FieldName != “Category_Name”)
return;
// Fill column headers with the specified colors.
e.Cache.FillRectangle(Color.Coral, e.Bounds);
e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect);
// Draw the filter and sort buttons.
foreach (DrawElementInfo info in e.Info.InnerElements) {
if (!info.Visible) continue;
ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo);
}
e.Handled = true;
};
}
发现info.Visible编译通不过,后来发现最简单的方法是用如下截图设置:
<