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
  • 相关阅读:
    JS调试debug
    避免使用 JS 特性 with(obj){}
    bit Byte KB MB GB TB 单位换算
    C语言中连接器介绍
    [bzoj3600]没有人的算术
    [bzoj4373]算术天才⑨与等差数列
    [bzoj4151][AMPPZ2014]The Cave
    [bzoj4906][BeiJing2017]喷式水战改
    [bzoj4908][BeiJing2017]开车
    [Codeforces Round#417 Div.2]
  • 原文地址:https://www.cnblogs.com/maozhh/p/904058.html
Copyright © 2011-2022 走看看