C#之重新绘制DataGridView的选择框

发布时间 2023-10-15 14:44:56作者: 小康0

/// <summary>
/// 重新绘制DataGridView的选择框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DgvUrlPath_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex == 0 && e.RowIndex == 0)
{
e.PaintBackground(e.CellBounds, true);
ControlPaint.DrawCheckBox(e.Graphics, e.CellBounds.X + 5, e.CellBounds.Y + 5,   //选择框的位置
e.CellBounds.Width - 10, e.CellBounds.Height - 10,    //选择框的大小
(bool)e.FormattedValue ? ButtonState.Checked : ButtonState.Normal);
e.Handled = true;
}
}