九月 16, 2008

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

Written by

在系统弹出对话框中往往带有Information、Question、Warnning、Error等系统图标,由于这些图标是系统自带的,所以可以为我们自己程序所用。

System.Drawing命名空间中有一个SystemIcons类,以静态属性方式提供了使用系统图标的便捷途径:

Public Properties

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

 

 

Category : .NetC#WPF其他

Tags :

发表评论

电子邮件地址不会被公开。

Proudly powered by WordPress and Sweet Tech Theme