using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Drawing;
using System.Windows.Forms;namespace WindowsControlLibrary1
{
    public enum PictureSource
    {
        Path,       //本地路径
        DataSoure,   //数据库
        resx,        //资源文件
        NetWrok,    //局域网
        WWW         //广域网
    }
    
    public partial class F2PictureBox : PictureBox
    {
        private PictureSource pictureSource;
        private string picturePath = "";             //问题在这里==============
        private bool isDataBind = false;
        private int idValue;
        private bool isCommit = false;
        private string commitFieldName = "";
        private string disFieldName = "";
        private string relatFieldName = "";
        private Image f2Image;        public F2PictureBox()
        {
            InitializeComponent();
        }        public F2PictureBox(IContainer container)
        {
            container.Add(this);            InitializeComponent();
        }        /// <summary>
        /// 引用图片类型
        /// </summary>
        [Category("F2")]
        [DefaultValue("")]
        [Description("引用图片类型,Path:本地路径;DataSoure:数据库;resx:资源文件;NetWrok:局域网;WWW:广域网")]
        public PictureSource F2PictureSource
        {
            get { return pictureSource; }
            set { pictureSource = value; }
        }        /// <summary>
        /// 图片来源路径
        /// </summary>
        [Category("F2")]
        [DefaultValue("")]
        [Description("图片来源路径")]
        public string F2Path
        {
            get { return picturePath; }
            set { picturePath = value; }
        }        /// <summary>
        /// 获取图片资源
        /// </summary>
        [Category("F2")]
        [DefaultValue("")]
        [Description("获取图片资源")]
        public Image F2Image
        {
            get
            {
                return f2Image;
            }
            set
            {
                switch (pictureSource)
                {
                    case PictureSource.Path:
                        string ext = picturePath.Trim();
                        string s = ext;
                        if (ext.Length > 4)
                        {
                            ext = ext.Substring(ext.Length - 3).ToUpper(); ;
                            if (ext == "BMP")
                            {
                                MessageBox.Show("BMP");
                                Bitmap bmp = new Bitmap(s);
                                this.f2Image = (Image)bmp;
                                this.Image = f2Image;
                            }
                        }
                        this.Refresh();
                        break;
                    case PictureSource.DataSoure:
                        break;
                    case PictureSource.resx:
                        break;
                    case PictureSource.NetWrok:
                        break;
                    case PictureSource.WWW:
                        break;
                }            }
        }    }
}以上的代码,如果在控件里给  picturePath 赋值:     
 private string picturePath = "c:\\abc.bmp";             //问题在这里==============可是实现效果,但是如果在设计期给这个控件的F2Path属性赋值就没用怎么解决啊?

解决方案 »

  1.   

    picturebox的image属性又不能override
      

  2.   

    没有很清楚的了解lz的意思,不过我想一下代码:
    /// <summary> 
    /// 图片来源路径 
    /// </summary> 
    [Category("F2")] 
    [DefaultValue("")] 
    [Description("图片来源路径")] 
    public string F2Path 

       get { return picturePath; } 
       set { picturePath = value; } 

    其中set之后是否应该进行通知变化以便进行render操作
    set 

       picturePath = value; 
       //此处添加通知方法
       this.OnF2PathChanged();
    }private void OnF2PathChanged()
    {
       this.Invalidate();
       //Or do sth...
    }