使用dataGridView控件常遇到的問題就是如何繪製行號,記錄在下以方便日後查看
//繪製表格行號
private void dataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
DataGridView dataGridView = (DataGridView)sender;
SolidBrush b = new SolidBrush(dataGridView.RowHeadersDefaultCellStyle.ForeColor);
e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dataGridView.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 6);
}