110,555
社区成员
发帖
与我相关
我的任务
分享
Rectangle cellBounds = new Rectangle();
string value = string.Empty;
int columnIndex = 0;
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex % 2 == 0&&e.ColumnIndex==0)
{
cellBounds = e.CellBounds;
if (e.Value != null)
value = e.Value.ToString();
columnIndex = e.ColumnIndex;
}
}
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
if (e.RowIndex % 2 == 0)
{
SolidBrush br = new SolidBrush(Color.White);
SolidBrush brString=new SolidBrush(dataGridView1.ForeColor);
e.Graphics.FillRectangle(br, cellBounds.Location.X - 1, cellBounds.Location.Y - 1, dataGridView1.Columns[columnIndex].Width, dataGridView1.Rows[e.RowIndex].Height);
e.Graphics.DrawString(value, dataGridView1.DefaultCellStyle.Font, brString, cellBounds.Location.X, cellBounds.Location.Y-20);
}
}