DataGridView中添加行号

来源:互联网 发布:qt交叉编译ubuntu下 编辑:程序博客网 时间:2024/06/06 05:36
 private void DGV_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            DataGridView dt = sender as DataGridView;
            System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X,
                e.RowBounds.Location.Y,
                dt.RowHeadersWidth - 4,
                e.RowBounds.Height);


            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                dt.RowHeadersDefaultCellStyle.Font,
                rectangle,
                dt.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);

        }



DGV.RowPostPaint += new DataGridViewRowPostPaintEventHandler(DGV_RowPostPaint);

0 0