1 private void dgvxCartCode_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) 2 { 3 this.PointRowNumber((DataGridView)sender, e); 4 } 5 6 /// <summary> 7 /// 给DataGridView控件画行号 8 /// </summary> 9 /// <param name="dgv"></param> 10 /// <param name="e"></param> 11 public void PointRowNumber(DataGridView dgv, DataGridViewRowPostPaintEventArgs e) 12 { 13 Rectangle rectangle = new Rectangle(e.RowBounds.X, e.RowBounds.Y, 14 dgv.RowHeadersWidth - 4, e.RowBounds.Height); 15 16 //参数 1.画笔 2.行号 3.字体样式 4.画笔位置 5.字体颜色 6.字体显示位置 17 TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), 18 dgv.RowHeadersDefaultCellStyle.Font, rectangle, 19 Color.Green, 20 TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter); 21 }
浙公网安备 33010602011771号