zoukankan      html  css  js  c++  java
  • 在DataGridView中显示行号

    通过处理DataGridView的RowPostPaint事件来显示行号

     1        /// <summary>
     2        /// 在DataGridView中显示行号,需要要处理DataGridView的RowPostPaint事件
     3        /// 在datagridview的行标题单元格中绘制行号
     4        /// </summary>
     5        /// <param name="sender"></param>
     6        /// <param name="e"></param>

     7        private void dgvCmd_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
     8        {
     9
    10            // Paint the row number on the row header.
    11            // The using statement automatically disposes the brush.
    12            DataGridView dgv = (DataGridView)sender;
    13            using (SolidBrush b = new SolidBrush(dgv.RowHeadersDefaultCellStyle.ForeColor))
    14            {
    15                e.Graphics.DrawString(e.RowIndex.ToString(System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + dgv.RowHeadersWidth / 2, e.RowBounds.Location.Y + (e.RowBounds.Height - e.InheritedRowStyle.Font.GetHeight()) / 2);
    16            }

    17            //SolidBrush用于定义单色画笔。画笔用于填充图形形状,如:矩形、椭圆、扇型、多边型和封闭路径。此类无法继承。
    18            //SolidBrush的构造函数:=new SolidBrush(Color color)
    19            /*DrawString方法:DrawString(string s,Font font,Brush brush,float x,float y)
    20                     s:要绘制的字符串
    21                     f:定义字符串的文本格式
    22             brush:确定所绘制的文本的颜色和纹理
    23                     x:左上角的x坐标
    24                     y:左上角的y坐标
    25             */

    26            //System.Globalization.CultureInfo.CurrentUICulture:提供区域性特定的格式设置信息
    27        }

    28
    29
  • 相关阅读:
    ES6 函数的扩展2
    css3 UI元素状态伪类选择器
    HTML5 矩阵变换
    ES6 let和const命令(4)
    ES6 let和const命令(3)
    ES6 let和const命令(2)
    JVM的内存区域划分(一)
    MySQL的四种事务隔离级别
    快速排序
    Struts2与SpringMVC的区别
  • 原文地址:https://www.cnblogs.com/maozhh/p/904058.html
Copyright © 2011-2022 走看看