private void dgvData_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (dgvData.Columns["编辑内容"].Index == e.ColumnIndex && e.RowIndex >= 0)
{
if ((e.RowIndex + 1) % 2 == 0)
{
SolidBrush Brush = new SolidBrush(dgvData.ColumnHeadersDefaultCellStyle.BackColor);
e.Graphics.FillRectangle(Brush, e.CellBounds);
Brush.Dispose();
e.Paint(e.CellBounds, DataGridViewPaintParts.All);
ControlPaint.DrawBorder(e.Graphics, e.CellBounds, dgvData.GridColor, 1, ButtonBorderStyle.Solid, dgvData.GridColor, 1, ButtonBorderStyle.Solid, dgvData.GridColor, 1, ButtonBorderStyle.Solid, dgvData.GridColor, 1, ButtonBorderStyle.Solid);
e.Handled = true;
}
}
}
C# DataGridView 单元格画线样式
最新推荐文章于 2026-04-26 02:01:00 发布
本文介绍了一种在DataGridView中设置交替行颜色的方法,通过在CellPainting事件中判断行索引的奇偶性来实现背景颜色的切换,提高了数据展示的可读性和美观度。

3万+

被折叠的 条评论
为什么被折叠?



