首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎样才能改变datagridview表头颜色?该如何解决

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

怎样才能改变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 

热点排行