C# 調用系統圖片

在系統彈出對話框中往往帶有Information、Question、Warnning、Error等系統圖標,由於這些圖標是系統自帶的,所以可以爲我們自己程序所用。

System.Drawing命名空間中有一個SystemIcons類,以靜態屬性方式提供了使用系統圖標的便捷途徑:

Public Properties

  Name Description
Public propertyStatic Application Gets an Icon object that contains the default application icon (WIN32: IDI_APPLICATION).
Public propertyStatic Asterisk Gets an Icon object that contains the system asterisk icon (WIN32: IDI_ASTERISK).
Public propertyStatic Error Gets an Icon object that contains the system error icon (WIN32: IDI_ERROR).
Public propertyStatic Exclamation Gets an Icon object that contains the system exclamation icon (WIN32: IDI_EXCLAMATION).
Public propertyStatic Hand Gets an Icon object that contains the system hand icon (WIN32: IDI_HAND).
Public propertyStatic Information Gets an Icon object that contains the system information icon (WIN32: IDI_INFORMATION).
Public propertyStatic Question Gets an Icon object that contains the system question icon (WIN32: IDI_QUESTION).
Public propertyStatic Warning Gets an Icon object that contains the system warning icon (WIN32: IDI_WARNING).
Public propertyStatic 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));

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章