如何更改 winform DataGridview 标题的颜色? [英] How to change the color of winform DataGridview header?

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

问题描述

我尝试过但没有成功.

有可能吗?

推荐答案

这样做的方法是将数据网格视图的 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天全站免登陆