数据网格视图标题网格颜色

发布于 2024-08-18 02:47:09 字数 436 浏览 4 评论 0原文

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

我们需要使网格控件上的标题分隔符的颜色与表单上的GridColor 的颜色相同。

输入图片此处的描述

我们尝试查看 DataGridView 控件的所有属性,并发现了一些看起来很有希望的有趣的东西,例如 DataGridViewAdvancedHeaderStyle 和 DataGridViewHeaderBorderStyle,但它们似乎都不允许您更改其上的颜色。

有谁知道如何在不使用 GDI+ 控件重新制作整个东西的情况下做到这一点?

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

We need to get the separators of the headers on the grid control to be the same colors as the GridColor on the form.

enter image description here

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伴我心暖 2024-08-25 02:47:09

好吧,我从来没有找到这个属性,所以我最终创建了一个自定义组件,并重载 OnPaint 事件处理程序以在现有组件上画一条线。

如果其他人遇到这篇文章寻找解决方案,这里是它的代码:

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

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
绝影如岚 2024-08-25 02:47:09

要更改 datagridview 中列标题的背景色,请为 EnableHeadersVisualStyles 选择 False。然后打开 ColumnHeadersDefaultCellStyle 并选择背景颜色。

To change the backcolor of the Column Headers in a datagridview, choose False for EnableHeadersVisualStyles. Then open ColumnHeadersDefaultCellStyle and choose the background color.

败给现实 2024-08-25 02:47:09

我看不到图片,但是玩一下怎么样?

DataGridView.ColumnBordersHeaderStyle
DataGridView.RowBordersHeaderStyle

I can't see the picture but what about playing with these?

DataGridView.ColumnBordersHeaderStyle
DataGridView.RowBordersHeaderStyle
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文