自定义控件,代码参见如下:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace UserDataGridView{public partial class UserDataGridView : DataGridView{ private Image m_Image;public UserDataGridView(){ InitializeComponent(); //this.m_Image = Image.FromFile("C:\\BG.jpg");}<summary>重写PaintBackground</summary>protected override void PaintBackground(Graphics graphics, Rectangle clipBounds, Rectangle gridBounds) { base.PaintBackground(graphics, clipBounds, gridBounds); graphics.DrawImage(this.m_Image, gridBounds); } /// <summary>设置背景图片</summary> public Image BackImage { get { return this.m_Image; } set { this.m_Image = value; base.Refresh(); // 重新加载 } } }}