通過CellPaint事件解決單元格選中邊框問題。
public void PaintBackground (
Rectangle clipBounds,
bool cellsPaintSelectionBackground
)
參數:
clipBounds
一個指定要繪製的 DataGridView 區域的 Rectangle。
cellsPaintSelectionBackground
true 用於使用 DataGridViewCell.InheritedStyle 的 SelectionBackColor 屬性的顏色繪製指定邊界的背景;false 用於使用 DataGridViewCell.InheritedStyle 的 BackColor 屬性的顏色繪製指定邊界的背景。
public void PaintContent (
Rectangle clipBounds
)
參數
clipBounds
一個指定要繪製的 DataGridView 區域的 Rectangle。
添加DataGridView的CellPaint事件,代碼如下:
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
e.Handled = true;
e.PaintBackground(e.CellBounds, true);
e.PaintContent(e.CellBounds);
}