2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Windowsのメッセージボックスに表示されるアイコン画像を取得する方法

Last updated at Posted at 2022-01-21

#やりたいこと
以下のコードで呼び出されるようなメッセージボックス

System.Windows.MessageBox.Show("タイトル", "メッセージ",
                               MessageBoxButton.YesNoCancel,
                               MessageBoxImage.Information);

に表示される以下のようなアイコン
systemicon_ast.png
を取得したい。

#方法

これらアイコンは以下のクラスのプロパティを参照することにより取得可能
System.Drawing.SystemIcons

SystemIconsのままではXAMLの<Image>に使えないのでImageSourceに変換する。

using System.Windows.Interop;
using System.Drawing;

//プロパティIconImage の定義は省略

//ImageSourceに変換
IconImage = Imaging.CreateBitmapSourceFromHIcon(
                               SystemIcons.Information.Handle,
                               Int32Rect.Empty,
                               BitmapSizeOptions.FromEmptyOptions());

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?