DataGridView添加行号以及自定义边框颜色

1 
//自定义边框颜色 注册到Paint事件
private void dataGridView1_Paint(object sender, PaintEventArgs e) 2 { 3 System.Drawing.Color a = System.Drawing.Color.FromArgb(101, 147, 207); // red, green, blue 4 Pen pen = new Pen(a); 5 e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, this.dataGridView1.Width - 1, this.dataGridView1.Height - 1)); 6 }

 

 1 
//添加行号,注册到RowPostPaint事件
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) 2 { 3 5 System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X, 6 e.RowBounds.Location.Y, 7 dataGridView1.RowHeadersWidth - 4, 8 e.RowBounds.Height); 9 10 TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), 11 dataGridView1.RowHeadersDefaultCellStyle.Font, 12 rectangle, 13 dataGridView1.RowHeadersDefaultCellStyle.ForeColor, 14 TextFormatFlags.VerticalCenter | TextFormatFlags.Right); 1
      }

 

你可能感兴趣的:(DataGridView添加行号以及自定义边框颜色)