Loading

DataGridView显示行号

     /// <summary>
        /// DataGridView显示行号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridWebResourceView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            string strRowNumber = (e.RowIndex + 1).ToString();
            while (strRowNumber.Length < dataGridWebResourceView.RowCount.ToString().Length) strRowNumber = "0" + strRowNumber;
            SizeF size = e.Graphics.MeasureString(strRowNumber, this.Font);
            if (dataGridWebResourceView.RowHeadersWidth < (int)(size.Width + 20)) dataGridWebResourceView.RowHeadersWidth = (int)(size.Width + 20);

            Brush b = SystemBrushes.ControlText;
            e.Graphics.DrawString(strRowNumber, this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
        }

  

posted @ 2015-01-21 14:44  jesn  阅读(167)  评论(0编辑  收藏  举报