C# winform datagridview rowheader 添加列名的方法

來源:互聯網
上載者:User

標籤:des   winform   datagridview   c   style   class   

        #region 寫行號事件        //在DataGridView控制項上選擇RowPostPaint事件        private void dgvJointList_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)        {            ((DataGridView)sender).fillRowHeaderIndex(e);        }        #endregion
        #region DataGridView的RowPostPaint事件中使用的添加列名的公用方法        /// <summary>        /// DataGridView的RowPostPaint事件中使用的添加列名的公用方法        /// </summary>        /// <param name="dgv">DataGridView名</param>        /// <param name="e">DataGridViewRowPostPaintEventArgs事件名</param>        public static void fillRowHeaderIndex(this DataGridView dgv, DataGridViewRowPostPaintEventArgs e)        {            Rectangle rectangle = new Rectangle            (                e.RowBounds.Location.X,                e.RowBounds.Location.Y,                dgv.RowHeadersWidth - 4,                e.RowBounds.Height            );            TextRenderer.DrawText            (                e.Graphics,                (e.RowIndex + 1).ToString(),                dgv.RowHeadersDefaultCellStyle.Font,                rectangle,                dgv.RowHeadersDefaultCellStyle.ForeColor,                TextFormatFlags.VerticalCenter | TextFormatFlags.Right            );        }        #endregion

 

  名稱 說明
 1 DrawText(IDeviceContext, String, Font, Point, Color) 使用指定的裝置上下文、字型和顏色在指定位置繪製指定文本。
 2 DrawText(IDeviceContext, String, Font, Rectangle, Color) 使用指定的裝置上下文、字型和顏色在指定界限中繪製指定文本。
 3 DrawText(IDeviceContext, String, Font, Point, Color, Color) 使用指定的裝置上下文、字型、顏色和背景色在指定位置繪製指定文本。
 4 DrawText(IDeviceContext, String, Font, Point, Color, TextFormatFlags) 使用指定的裝置上下文、字型、顏色和格式說明在指定位置繪製指定文本。
 5 DrawText(IDeviceContext, String, Font, Rectangle, Color, Color) 使用指定的裝置上下文、字型、顏色和背景色在指定界限中繪製指定文本。
 6 DrawText(IDeviceContext, String, Font, Rectangle, Color, TextFormatFlags) 使用指定的裝置上下文、字型、顏色和格式說明在指定界限中繪製指定文本。
 7 DrawText(IDeviceContext, String, Font, Point, Color, Color, TextFormatFlags) 使用指定的裝置上下文、字型、顏色、背景色和格式說明在指定位置繪製指定文本
 8 DrawText(IDeviceContext, String, Font, Rectangle, Color, Color, TextFormatFlags) 使用指定的裝置上下文、字型、顏色、背景色和格式說明在指定界限中繪製指定文本。
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.