解决方案 »

  1.   

    昨天试了一晚上oncellpaiting和onpaint 画不出来,今天在尝试OnRowPostPaint
    版主能否给点代码借鉴下...
      

  2.   

    在oncellpaiting将单元格背景色和边框线绘制好了,为什么选中行的背景色设置无效,前景色却有效,求大神解释下...
      

  3.   

      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没有效果