Winform讓DataGridView左側顯示圖片
更新時間:2016年05月30日 12:04:26 作者:秦風
本文主要介紹在如何讓DataGridView左側顯示圖片,這里主要講解重寫DataGridView的OnRowPostPaint方法,需要的朋友可以參考下。
效果圖片
重寫DataGridView的OnRowPostPaint方法或者直接在DataGridView的RowPostPaint事件里寫,如下(重寫DataGridView的OnRowPostPaint方法)
using System; using System.Text; using System.Windows.Forms; using System.Drawing; namespace Test { class DataGridViewEx : DataGridView { SolidBrush solidBrush; public DataGridViewEx() { solidBrush = new SolidBrush(this.RowHeadersDefaultCellStyle.ForeColor); } protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e) { e.Graphics.DrawImage(Image對象, e.RowBounds.Location.X, e.RowBounds.Location.Y); base.OnRowPostPaint(e); } } }
以上就是重寫DataGridView的OnRowPostPaint方法,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關文章
c# winform讀取xml文件創(chuàng)建菜單的代碼
動態(tài)創(chuàng)建菜單使得程序靈活性大大增加,本文根據讀取xml文件中的配置菜單項來動態(tài)創(chuàng)建菜單,代碼如下2013-09-09C#實現(xiàn)win10 uwp 右擊浮出窗在點擊位置
本文主要讓MenuFlyout出現(xiàn)在我們右擊位置。我們建一個ListView,然后綁定后臺,在我們ListView要右擊顯示我們的浮出,要求我們的浮出在我們點擊位置2016-10-10