现在的位置: 首页 > 综合 > 正文

C#中如何取得并使用Windows系统图标

2012年09月16日 ⁄ 综合 ⁄ 共 1230字 ⁄ 字号 评论关闭

在系统弹出对话框中往往带有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));

 

 

抱歉!评论已关闭.