加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vb.net – 如何更改datagridView标头颜色

发布时间:2020-12-17 07:26:43 所属栏目:百科 来源:网络整理
导读:现在,datagridView标题背景颜色以灰色显示.我想改成差异 颜色. 我在ColumnHeaderDefaultCellStyle中更改了背景颜色,但没有任何改变. 这该怎么做. 解决方法 在datagridView中,您可以使用 DataGridViewCellStyle更改标题颜色,请参阅以下代码 ' Set the selecti
现在,datagridView标题背景颜色以灰色显示.我想改成差异
颜色.

我在ColumnHeaderDefaultCellStyle中更改了背景颜色,但没有任何改变.

这该怎么做.

解决方法

在datagridView中,您可以使用 DataGridViewCellStyle更改标题颜色,请参阅以下代码

' 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 Event Handler的一个重要事件看看this

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读