在系统弹出对话框中往往带有Information、Question、Warnning、Error等系统图标,由于这些图标是系统自带的,所以可以为我们自己程序所用。
System.Drawing命名空间中有一个SystemIcons类,以静态属性方式提供了使用系统图标的便捷途径:
Public Properties
Name | Description | |
---|---|---|
Application | Gets an Icon object that contains the default application icon (WIN32: IDI_APPLICATION). | |
Asterisk | Gets an Icon object that contains the system asterisk icon (WIN32: IDI_ASTERISK). | |
Error | Gets an Icon object that contains the system error icon (WIN32: IDI_ERROR). | |
Exclamation | Gets an Icon object that contains the system exclamation icon (WIN32: IDI_EXCLAMATION). | |
Hand | Gets an Icon object that contains the system hand icon (WIN32: IDI_HAND). | |
Information | Gets an Icon object that contains the system information icon (WIN32: IDI_INFORMATION). | |
Question | Gets an Icon object that contains the system question icon (WIN32: IDI_QUESTION). | |
Warning | Gets an Icon object that contains the system warning icon (WIN32: IDI_WARNING). | |
WinLogo | Gets an Icon object that contains the Windows logo icon (WIN32: IDI_WINLOGO). |
需要注意的是,它是属于System.Drawing命名空间的,就是说它是GDI+的函数。
要在WPF中使用系统图标也是一件非常困难的事,微软提供了WPF的矢量绘图系统,可是它与传统的GDI、GDI+之间的转换并不是很全面和便利,要为WPF中的Image控件的Source指定图片数据源,你需要使用System.Windows.Interop下的Imaging来做转换:
Icon icon = System.Drawing.SystemIcons.Information;
BitmapSource source1 = Imaging.CreateBitmapSourceFromHIcon(icon.Handle,new Int32Rect(0,0,32,32), BitmapSizeOptions.FromWidth(32));