Icon 類別

定義

代表一個 Windows 圖示,這是一個用來表示物件的小型點陣圖圖像。 圖示可以視為透明位圖,不過其大小是由系統決定。

public ref class Icon sealed : MarshalByRefObject, ICloneable, IDisposable, System::Runtime::Serialization::ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))]
[System.Serializable]
public sealed class Icon : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(false)]
public sealed class Icon : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))]
public sealed class Icon : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter("System.Drawing.IconConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")]
public sealed class Icon : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))>]
[<System.Serializable>]
type Icon = class
    inherit MarshalByRefObject
    interface ICloneable
    interface IDisposable
    interface ISerializable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(false)>]
type Icon = class
    inherit MarshalByRefObject
    interface ISerializable
    interface ICloneable
    interface IDisposable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))>]
[<System.Serializable>]
type Icon = class
    inherit MarshalByRefObject
    interface ISerializable
    interface ICloneable
    interface IDisposable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))>]
type Icon = class
    inherit MarshalByRefObject
    interface ICloneable
    interface IDisposable
    interface ISerializable
[<System.ComponentModel.TypeConverter("System.Drawing.IconConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")>]
type Icon = class
    inherit MarshalByRefObject
    interface ICloneable
    interface IDisposable
    interface ISerializable
Public NotInheritable Class Icon
Inherits MarshalByRefObject
Implements ICloneable, IDisposable, ISerializable
繼承
屬性
實作

範例

以下程式碼範例示範如何使用此 ToBitmap 方法。 此範例設計用於 Windows 表單。 建立一個表單,然後把以下程式碼貼上去。 在表單的事件處理程序中呼叫該IconToBitmap方法,並傳遞PaintePaintEventArgs

private:
   void IconToBitmap( PaintEventArgs^ e )
   {
      // Construct an Icon.
      System::Drawing::Icon^ icon1 = gcnew System::Drawing::Icon( SystemIcons::Exclamation,40,40 );

      // Call ToBitmap to convert it.
      Bitmap^ bmp = icon1->ToBitmap();

      // Draw the bitmap.
      e->Graphics->DrawImage( bmp, Point(30,30) );
   }
private void IconToBitmap(PaintEventArgs e)
{
    // Construct an Icon.
    Icon icon1 = new Icon(SystemIcons.Exclamation, 40, 40);

    // Call ToBitmap to convert it.
    Bitmap bmp = icon1.ToBitmap();

    // Draw the bitmap.
    e.Graphics.DrawImage(bmp, new Point(30, 30));
}
Private Sub IconToBitmap(ByVal e As PaintEventArgs)

    ' Construct an Icon.
    Dim icon1 As New Icon(SystemIcons.Exclamation, 40, 40)

    ' Call ToBitmap to convert it.
    Dim bmp As Bitmap = icon1.ToBitmap()

    ' Draw the bitmap.
    e.Graphics.DrawImage(bmp, New Point(30, 30))
End Sub

備註

你可以從檔案、串流或嵌入式資源中建構 Icon 物件。 關於構造子列表,請參見 Icon。 你也可以用這個Icon方法把 轉ToBitmap成點陣圖。

Note

在 .NET 6 和更新版本中,只有 Windows作系統才支援包含此類型的 System.Drawing.Common 套件。 跨平台應用程式使用此類會引發編譯時警告及執行時異常。 如需詳細資訊,請參閱 僅限 Windows 上支援的 System.Drawing.Common。

一個圖示資源可以包含多個圖示影像。 一個圖示檔案可能包含多種大小與色深的影像。 應用程式中使用的映像檔取決於作業系統和設定。 以下列表詳細說明圖示的典型尺寸:

  • 16 像素 x 16 像素

  • 32 像素 x 32 像素

  • 48 像素 x 48 像素

建構函式

名稱 Description
Icon(Icon, Int32, Int32)

初始化該類別的新實例 Icon ,並嘗試尋找符合請求大小的圖示版本。

Icon(Icon, Size)

初始化該類別的新實例 Icon ,並嘗試尋找符合請求大小的圖示版本。

Icon(Stream, Int32, Int32)

從指定的資料流初始化該類別的新實例 Icon ,並以指定的寬度與高度。

Icon(Stream, Size)

從指定的串流中初始化該類別中指定大小的新實例 Icon

Icon(Stream)

從指定的資料流中初始化該類別的新實例 Icon

Icon(String, Int32, Int32)

初始化一個新的類別實例 Icon ,並以指定的寬度和高度從指定的檔案中初始化。

Icon(String, Size)

從指定檔案初始化該類別中指定大小的新實例 Icon

Icon(String)

從指定的檔案名稱初始化該 Icon 類別的新實例。

Icon(Type, String)

從指定組合語言中的資源初始化該 Icon 類別的新實例。

屬性

名稱 Description
Handle

他會Windows這個Icon。 這不是手柄的複製品;不要放開它。

Height

理解這個 Icon重點。

Size

懂得這個 Icon大小。

Width

得到這個 Icon寬度。

方法

名稱 Description
Clone()

複製 , Icon產生一個複製的映像。

CreateObjRef(Type)

建立一個物件,包含產生代理伺服器所需的所有相關資訊,用於與遠端物件通訊。

(繼承來源 MarshalByRefObject)
Dispose()

釋放所有被使用。Icon

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
ExtractAssociatedIcon(String)

回傳包含於指定檔案中的圖示表示。

ExtractIcon(String, Int32, Boolean)

從給定 filePath的 中提取指定的圖示。

ExtractIcon(String, Int32, Int32)

從給定 filePath的 中提取指定的圖示。

Finalize()

允許對象嘗試釋放資源,並在垃圾收集回收之前執行其他清除作業。

FromHandle(IntPtr)

從指定的Windows柄建立 GDI+ Icon,圖示(HICON)。

GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetLifetimeService()
已淘汰.

擷取控制這個實例存留期原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetType()

取得目前實例的 Type

(繼承來源 Object)
InitializeLifetimeService()
已淘汰.

取得存留期服務物件,以控制這個實例的存留期原則。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 對象的淺層複本。

(繼承來源 MarshalByRefObject)
Save(Stream)

將此 Icon 資料儲存到指定的輸出 Stream中。

ToBitmap()

將此 Icon 轉換為 GDI+ Bitmap

ToString()

會得到一個人類可讀的字串,描述 Icon

明確介面實作

名稱 Description
ISerializable.GetObjectData(SerializationInfo, StreamingContext)

在 a SerializationInfo 中填入序列化目標物件所需的資料。

適用於

另請參閱