首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# 依据名字获取图片

2012-08-27 
C# 根据名字获取图片。我现在把图片添加到资源文件里面了。比如有10个 名字分别为_0,_1,_2,_3........平时都

C# 根据名字获取图片。
我现在把图片添加到资源文件里面了。比如有10个 名字分别为_0,_1,_2,_3........

平时都是这样的弄 Properties.Resources._0 ;

属性的名字从资源文件里面获取图片。怎么弄? 现在设置属性,怎么对应上,

C# code
string imageName;        public string ImageName        {            get { return imageName; }            set            {                imageName = value;                //this.BackgroundImage = Properties.Resources._0;                switch (ImageName)//这样的是不可取的 因为图片要是有很多的话,一点不好。                {                    case "_0":                        this.BackgroundImage = Properties.Resources._0;                        break;                    case "_1":                        this.BackgroundImage = Properties.Resources._1;                        break;                    default: break;                }            }        }

 

[解决办法]
C# code
        string imageName;         public string ImageName        {            get { return imageName; }            set            {                imageName = value;                this.BackgroundImage = Properties.Resources.ResourceManager.GetObject(value) as Image;            }        } 

热点排行