如何更改winform DataGridview头的颜色? [英] how to change the color of winform DataGridview header?

查看:346
本文介绍了如何更改winform DataGridview头的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有成功尝试去做。

I have tried to do it without success. Is it possible ?

推荐答案

这样做的方法是设置 EnableHeadersVisualStyles 将数据网格视图标记为 False ,并通过 ColumnHeadersDefaultCellStyle.BackColor 属性设置背景颜色。例如,要将背景颜色设置为蓝色,请使用以下内容(如果您愿意,请在设计器中设置):

The way to do this is to set the EnableHeadersVisualStyles flag for the data grid view to False, and set the background colour via the ColumnHeadersDefaultCellStyle.BackColor property. For example, to set the background colour to blue, use the following (or set in the designer if you prefer):

_dataGridView.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue;
_dataGridView.EnableHeadersVisualStyles = false;

如果您没有设置 EnableHeadersVisualStyles 到False,那么您对标题样式所做的更改将不会生效,因为网格将使用当前用户默认主题的样式。该属性的MSDN文档是这里

If you do not set the EnableHeadersVisualStyles flag to False, then the changes you make to the style of the header will not take effect, as the grid will use the style from the current users default theme. The MSDN documentation for this property is here.

这篇关于如何更改winform DataGridview头的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆