0

案例:我有一个桌面应用程序,我需要根据登录的供应商在其中显示自定义图像。因此,在 中App.config,图像文件被添加为键:

<add key="Logo" value="companylogo_2.jpg"/>

如何ToolstripLabel控制消费?

注意: 在 App.config 文件中,value 不包含图像的完整路径,仅包含图像的名称

试验:
1。

smallImageList.Images.Add(Image.FromFile(ConfigurationSettings.AppSettings["Logo"]));

2.

string CurrDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
smallImageList.Images.Add(Image.FromFile(Path.Combine(CurrDirectory,ConfigurationSettings.AppSettings["Logo"])));
4

1 回答 1

1

感谢您的零帮助!无论如何,我想通了。

步骤:
从以下位置读取值App.config

public string imgLogo = System.Configuration.ConfigurationSettings.AppSettings["Logo"].ToString();

使用:获取完整路径Assembly.GetExecutingAssembly().Location

`System.Drawing.Image myImage = Image.FromFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\" + imgLogo + "");`

赋值 toolStripLabel

toolStripLabel1.Image = myImage;
于 2016-08-17T05:12:30.670 回答