0

ケース:ログインしているベンダーごとにカスタマイズされた画像を表示する必要があるデスクトップ アプリケーションがあります。したがって、App.configでは、イメージ ファイルがキーとして追加されます。

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

コントロールでそれを消費する方法はToolstripLabel

注: App.config ファイルでは、値にイメージのフル パスは含まれず、イメージの名前のみが含まれます。

トライアル:
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().Locationas:を使用して完全なパスを取得します。

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

次のように値を代入し toolStripLabel ます

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