c# 消除datagridview 單元格選中邊框

通過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);

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章