在系統彈出對話框中往往帶有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));