这是我的细胞绘画方法。
DataGridView grid = (DataGridView)sender;
if ( e.RowIndex == -1 || e.ColumnIndex == -1 )
{ return; }
if ( ( grid.Rows [ e.RowIndex ].Cells [ e.ColumnIndex ].Value == null ) )
return;
Brush gridBrush = new SolidBrush(GridList[0].GridColor),backColorBrush = new SolidBrush(e.CellStyle.BackColor);
Pen gridLinePen = new Pen(gridBrush);
// Erase the cell.
e.Graphics.FillRectangle ( backColorBrush, e.CellBounds );
// Draw the grid lines (only the right and bottom lines;
// DataGridView takes care of the others).
e.Graphics.DrawLine ( gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1, …Run Code Online (Sandbox Code Playgroud)