如何更改datagridView标头颜色 [英] How to change the datagridView Header color
本文介绍了如何更改datagridView标头颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在,datagridView标题背景颜色显示为灰色.我想改变一下 颜色.
Now the datagridView Header Background color is showing in Gray. I want to change to differenct color.
我更改了ColumnHeaderDefaultCellStyle
中的背景颜色,但没有任何改变.
I Changed the background color in ColumnHeaderDefaultCellStyle
, but nothing changed.
如何做到这一点.
推荐答案
In datagridView you can change the Header color by using DataGridViewCellStyle, see the following code
' Set the selection background color for all the cells.
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.White
dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Black
' Set RowHeadersDefaultCellStyle.SelectionBackColor so that its default
' value won't override DataGridView.DefaultCellStyle.SelectionBackColor.
dataGridView1.RowHeadersDefaultCellStyle.SelectionBackColor = Color.Empty
' Set the background color for all rows and for alternating rows.
' The value for alternating rows overrides the value for all rows.
dataGridView1.RowsDefaultCellStyle.BackColor = Color.LightGray
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.DarkGray
' Set the row and column header styles.
dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Black
dataGridView1.RowHeadersDefaultCellStyle.BackColor = Color.Black
使用DataGridViewCellStyle,标题颜色将更改,但标题部分中的列分隔符将不会出现.因此,这里是OnPaint事件处理程序的重写事件,请查看此
Using the DataGridViewCellStyle, your header color will changes but a seperator for columns in the header section will not appear. So, heres a overrided event of OnPaint Event Handler have a look at this
这篇关于如何更改datagridView标头颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文