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);
}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。