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

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

问题描述

这是一个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天全站免登陆