2016-11-08 85 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-正在編輯)描述編輯時的自定義邊框問題。 –