读书人

怎样才能改变datagridview表头颜色?该

发布时间: 2012-03-18 13:55:38 作者: rapoo

怎样才能改变datagridview表头颜色?
如题:
datagridview表头默认颜色为灰白色,怎样才改变?

ColumnHeadersDefaultCellStyle.BackColor 设置了不行?


[解决办法]

VB.NET code
dim mLinearColor1 As Color = Color.FromArgb(248, 250, 251)dim mLinearColor2 As Color = Color.FromArgb(196, 207, 224)dim mGridColor As Color = Color.FromArgb(120, 147, 191)    '网格线的颜色dim mBorderColor As Color = Color.MediumBlue               '控件边框的颜色dim mMouseInColor As Color = Color.Orange                  '鼠标进入时控件的颜色dim mHasFocusedColor As Color = Color.DarkCyan             '控件的焦点框颜色 Private Sub MyDataGridView_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles Me.CellPainting        Dim StrFormat As New System.Drawing.StringFormat        Dim Rect As Rectangle = New Rectangle(e.CellBounds.X - 1, e.CellBounds.Y, e.CellBounds.Width, e.CellBounds.Height - 1)        Dim LinearGradientBrush As New Drawing2D.LinearGradientBrush(Rect, mLinearColor1, mLinearColor2, Drawing2D.LinearGradientMode.Vertical)        Try            If e.RowIndex = -1 Or e.ColumnIndex = -1 Then                e.Graphics.FillRectangle(LinearGradientBrush, Rect)                e.Graphics.DrawRectangle(New Pen(GridColor), Rect)                e.PaintContent(e.CellBounds)                e.Handled = True            End If        Catch ex As Exception        Finally            Rect = Nothing            StrFormat.Dispose()            If LinearGradientBrush IsNot Nothing Then LinearGradientBrush.Dispose()        End TryEnd Sub 

读书人网 >C#

热点推荐