zoukankan      html  css  js  c++  java
  • DataGridView添加行号

    自己在做WINFORM小玩意的时候需要在datagridview上显示行号,上网搜索一下,找到如下代码,不错,先记录下来了。

        在RowPostPaint事件中画出来

            // 绘制行号
            private void gvdata_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
            {
                
    try
                {

                    Rectangle rectangle 
    = new Rectangle(e.RowBounds.Location.X,

                        Convert.ToInt32(e.RowBounds.Location.Y 
    + (e.RowBounds.Height - gvdata.RowHeadersDefaultCellStyle.Font.Size) / 2),

                        gvdata.RowHeadersWidth 
    - 4, e.RowBounds.Height);

                    TextRenderer.DrawText(e.Graphics, (e.RowIndex 
    + 1).ToString(),

                        gvdata.RowHeadersDefaultCellStyle.Font, rectangle, gvdata.RowHeadersDefaultCellStyle.ForeColor,

                        TextFormatFlags.Right);



                }

                
    catch (Exception ex)
                {

                    Console.Write(
    "dgv1_RowPostPaint:" + ex.Message);

                }
            }

    效果如图:

     

    撸码:复制、粘贴,拿起键盘就是“干”!!!
  • 相关阅读:
    RT-thread内核之事件
    RT-thread内核之互斥量
    RT-thread内核之信号量
    RT-thread内核之进程间通信
    RT-thread内核之异常与中断
    RT-thread内核之IO设备管理系统
    RT-thread内核之小内存管理算法
    RT-thread内核之系统时钟
    RT-thread内核之定时器管理
    s19文件格式详解
  • 原文地址:https://www.cnblogs.com/niunan/p/1707574.html
Copyright © 2011-2022 走看看