数据网格视图标题网格颜色 [英] Data grid view header Grid color

查看:159
本文介绍了数据网格视图标题网格颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个VB .NET应用程序,我们在Datagrid视图中显示SQL语句的输出。使用.NET 2005。

This is a VB .NET application where we are showing the output of a SQL statement in a Datagrid view. using .NET 2005.

我们需要让网格控件上的标题的分隔符与窗体上的GridColor相同。见下图:

We need to get the seperators of the headers on the grid control to be the same colors as the GridColor on the form. See the picture below:

我们试图查看DataGridView控件的所有属性,并发现了一些有希望的有趣的东西,如DataGridViewAdvancedHeaderStyle和DataGridViewHeaderBorderStyle,但没有似乎允许你改变它上面的颜色。

We've tried looking through all of the properties of the DataGridView control, and found some interesting things that looked promising such as the DataGridViewAdvancedHeaderStyle, and DataGridViewHeaderBorderStyle, but none of it seems to allow you to change the colors on it.

有没有人知道如何做到这一点,而不用GDI +控件重新整理整个事情?

Does anyone know how to do this without remaking the entire thing with a GDI+ control?

推荐答案

嗯,我从来没有找到一个属性,所以我最终创建一个自定义组件,并重载OnPaint事件处理程序来绘制一行超过现有的。

Well, I never did find a property for this, so I ended up creating a custom component, and overloading the OnPaint event handler to draw a line over the existing one.

如果有人遇到这个帖子找到解决方案,这里是代码:

Here is the code for it if anyone else ever comes across this post looking for a solution:

Private Sub CustomDataGridView_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    Dim g As Graphics = e.Graphics
    Dim pen As New Pen(Me.GridColor)
    Dim TWidth As Integer = 2
    Dim HeaderWidth As Integer = 0
    If Me.RowHeadersVisible Then
        HeaderWidth = Me.RowHeadersWidth
    End If
    For Each column As DataGridViewColumn In Me.Columns
        Dim x As Integer = HeaderWidth + TWidth - 1
        TWidth += column.Width
        Dim top As Integer = column.HeaderCell.ContentBounds.Top
        Dim bottom As Integer = column.HeaderCell.ContentBounds.Bottom + 1
        pen.Width = 2
        g.DrawLine(pen, x, top, x, bottom)
    Next column
End Sub

这篇关于数据网格视图标题网格颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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