C#中如何取得並使用Windows系統表徵圖

來源:互聯網
上載者:User

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

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.