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

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

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

Public Properties

 Name Description
Public propertyStaticApplication Gets an Icon object that contains the default application icon (WIN32: IDI_APPLICATION).
Public propertyStaticAsterisk Gets an Icon object that contains the system asterisk icon (WIN32: IDI_ASTERISK).
Public propertyStaticError Gets an Icon object that contains the system error icon (WIN32: IDI_ERROR).
Public propertyStaticExclamation Gets an Icon object that contains the system exclamation icon (WIN32: IDI_EXCLAMATION).
Public propertyStaticHand Gets an Icon object that contains the system hand icon (WIN32: IDI_HAND).
Public propertyStaticInformation Gets an Icon object that contains the system information icon (WIN32: IDI_INFORMATION).
Public propertyStaticQuestion Gets an Icon object that contains the system question icon (WIN32: IDI_QUESTION).
Public propertyStaticWarning Gets an Icon object that contains the system warning icon (WIN32: IDI_WARNING).
Public propertyStaticWinLogo 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));

 

 

转载于:https://www.cnblogs.com/khler/archive/2008/09/16/1291925.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值