c# 控件添加属性

 public partial class UserDataGridView : DataGridView
    {
        private Image m_Image;

        public UserDataGridView()
        {
            InitializeComponent();
            //this.m_Image = Image.FromFile("C:\\BG.jpg");   
            //this.m_Image = Resources.网格背景;
        }

        ///<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();  // 重新加载   
            }
        }

 

posted @ 2013-04-26 16:52  louiskoo  阅读(474)  评论(0编辑  收藏  举报