2016-11-08 108 views
0

我想基于细胞变化的datagridview cellstyle边框颜色

此背景颜色更改单元格边框的颜色是什么,我已经使用

'Draw custom cell borders. 
     Using Brush As New SolidBrush(grdList.ColumnHeadersDefaultCellStyle.BackColor) 
      e.Graphics.FillRectangle(Brush, e.CellBounds) 
     End Using 

     e.Paint(e.CellBounds, DataGridViewPaintParts.All And Not DataGridViewPaintParts.ContentBackground) 
     Debug.Print(e.CellStyle.BackColor.ToString) 
     ControlPaint.DrawBorder(e.Graphics, e.CellBounds, e.CellStyle.BackColor, 1, _ 
           ButtonBorderStyle.Solid, e.CellStyle.BackColor, 1, _ 
           ButtonBorderStyle.Solid, e.CellStyle.BackColor, 1, _ 
           ButtonBorderStyle.Solid, Color.Black, 1, _ 
           ButtonBorderStyle.Solid) 

这是结果

enter image description here

我不知道目前看到的白线

+0

你不想白色的,但你想要什么?它看起来像你试图画黑线。 – Plutonix

回答

1

正如你可以设置边框样式哟没有一个选项:

Me.DataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None 

然后处理CellPainting事件和油漆边界:

Private Sub DataGridView1_CellPainting(sender As Object, _ 
    e As DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting 

    If (e.ColumnIndex < 0 OrElse e.RowIndex < 0) Then Return 
    e.Paint(e.CellBounds, DataGridViewPaintParts.All) 
    Dim r = e.CellBounds 
    e.Graphics.DrawLine(Pens.Black, r.Left, r.Top, r.Right, r.Top) 
    e.Graphics.DrawLine(Pens.Black, r.Left, r.Bottom, r.Right, r.Bottom) 
    e.Handled = True 
End Sub 

enter image description here

+0

如果您在应用答案时遇到任何问题,请告知我。另外你可能想看看[这篇文章](http://stackoverflow.com/questions/32154847/how-do-you-draw-a-border-around-a-datagridview-cell-while-its-正在编辑)描述编辑时的自定义边框问题。 –