www.pudn.com > PPC_Weather.rar > PictureBoxURL.cs


using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Windows.Forms; 
using System.Drawing; 
 
namespace PPC_Weather 
{ 
    public class PictureBoxURL:PictureBox 
    { 
        public event EventHandler PicUrlChanging; 
        public event EventHandler PicUrlChanged; 
 
        private string picUrl; 
        public string PicUrl 
        { 
            get { return picUrl; } 
            set 
            { 
                if (!string.IsNullOrEmpty(value)) 
                { 
                    OnPicUrlChanging(EventArgs.Empty); 
                    picUrl = value; 
                    this.Image = this.GetImage(value); 
                    OnPicUrlChanged(EventArgs.Empty); 
                } 
            } 
        } 
 
        protected virtual void OnPicUrlChanging(EventArgs e) { 
            if (PicUrlChanging!=null) 
            { 
                PicUrlChanging(this, e); 
            } 
        } 
 
        protected virtual void OnPicUrlChanged(EventArgs e) 
        { 
            if (PicUrlChanged != null) 
            { 
                PicUrlChanged(this, e); 
            } 
        } 
 
        //»ñÈ¡µ±Ç°Í¼Æ¬ 
        private Image GetImage(string strFile) 
        { 
            if (strFile.Length == 0) return null; 
 
            string strPath = App.GetAppPath() + "\\pic\\" + strFile; 
            if (System.IO.File.Exists(strPath)) 
            { 
                return new Bitmap(strPath); 
            } 
            else 
            { 
                return null; 
            } 
        } 
 
    } 
}