Protected Overrides Sub OnCellPainting(ByVal e As DataGridViewCellPaintingEventArgs) MyBase.OnCellPainting(e) AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue Dim r As Rectangle = e.CellBounds Dim p As Pen = New Pen(Color.SkyBlue, 2) r.Offset(New Point(0, 0)) If (e.RowIndex = -1) Then e.CellStyle.BackColor = Color.AliceBlue e.CellStyle.Font = New Drawing.Font(e.CellStyle.Font, FontStyle.Bold) End If Using b As Drawing2D.LinearGradientBrush = New Drawing2D.LinearGradientBrush(e.CellBounds, e.CellStyle.BackColor, e.CellStyle.BackColor, 1, True) e.Graphics.FillRectangle(b, e.CellBounds) End Using e.CellStyle.SelectionBackColor = Color.Color.Red e.CellStyle.SelectionForeColor = Color.FromArgb(10, 50, 205, 50) e.Graphics.DrawRectangle(p, r) e.Graphics.DrawRectangle(p, r) e.PaintContent(e.ClipBounds) e.Handled = True End Sub重绘代码,麻烦高手看下为什么e.CellStyle.SelectionBackColor = Color.Red没有效果
版主能否给点代码借鉴下...
MyBase.OnCellPainting(e)
AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue
Dim r As Rectangle = e.CellBounds
Dim p As Pen = New Pen(Color.SkyBlue, 2)
r.Offset(New Point(0, 0))
If (e.RowIndex = -1) Then
e.CellStyle.BackColor = Color.AliceBlue
e.CellStyle.Font = New Drawing.Font(e.CellStyle.Font, FontStyle.Bold)
End If
Using b As Drawing2D.LinearGradientBrush = New Drawing2D.LinearGradientBrush(e.CellBounds, e.CellStyle.BackColor, e.CellStyle.BackColor, 1, True)
e.Graphics.FillRectangle(b, e.CellBounds)
End Using
e.CellStyle.SelectionBackColor = Color.Color.Red
e.CellStyle.SelectionForeColor = Color.FromArgb(10, 50, 205, 50)
e.Graphics.DrawRectangle(p, r)
e.Graphics.DrawRectangle(p, r)
e.PaintContent(e.ClipBounds)
e.Handled = True
End Sub重绘代码,麻烦高手看下为什么e.CellStyle.SelectionBackColor = Color.Red没有效果