Icon 類別

定義

代表 Windows 圖示,這個圖示為用來代表物件的小型點陣圖影像。 雖然圖示的大小是由系統決定,但是圖示仍然可以視為透明的點陣圖。

public ref class Icon sealed : MarshalByRefObject, ICloneable, IDisposable, System::Runtime::Serialization::ISerializable
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))]
public sealed class Icon : 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
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
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))>]
type Icon = class
    inherit MarshalByRefObject
    interface ICloneable
    interface IDisposable
    interface 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
Public NotInheritable Class Icon
Inherits MarshalByRefObject
Implements ICloneable, IDisposable, ISerializable
繼承
屬性
實作

範例

下列程式碼範例會示範如何使用 ToBitmap 方法。 此範例的設計目的是要與Windows Forms搭配使用。 建立表單,並將下列程式碼貼到其中。 IconToBitmap在表單的 Paint 事件處理常式中呼叫 方法,並 e 傳遞為 PaintEventArgs

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 。 您也可以使用 ToBitmap 方法,將 轉換成 Icon 點陣圖。

注意

在 .NET 6 和更新版本中,只有 Windows 作業系統才支援包含此類型的 System.Drawing.Common 套件。 在跨平臺應用程式中使用此類型會導致編譯時期警告和執行時間例外狀況。 如需詳細資訊,請參閱 僅限 Windows 上支援的 System.Drawing.Common

圖示資源可以包含多個圖示影像。 一個圖示檔案可能包含數個大小和色彩深度的影像。 應用程式中使用的映射取決於作業系統和設定。 下列清單詳細說明圖示的一般大小:

  • 16 圖元 x 16 圖元

  • 32 圖元 x 32 圖元

  • 48 圖元 x 48 圖元

建構函式

Icon(Icon, Int32, Int32)

初始化 Icon 類別的新執行個體,並嘗試尋找符合所要求大小的圖示版本。

Icon(Icon, Size)

初始化 Icon 類別的新執行個體,並嘗試尋找符合所要求大小的圖示版本。

Icon(Stream)

從指定的資料流,初始化 Icon 類別的新執行個體。

Icon(Stream, Int32, Int32)

使用指定的寬度和高度,從指定的資料流初始化 Icon 類別的新執行個體。

Icon(Stream, Size)

從指定的資料流,以指定之大小初始化 Icon 類別的新執行個體。

Icon(String)

從指定的檔案名稱初始化 Icon 類別的新執行個體。

Icon(String, Int32, Int32)

使用來自指定檔案的指定寬度和高度,初始化 Icon 類別的新執行個體。

Icon(String, Size)

從指定的資料流,以指定之大小初始化 Icon 類別的新執行個體。

Icon(Type, String)

從指定的組件中的資源,初始化 Icon 類別的新執行個體。

屬性

Handle

取得這個 Icon 的 Windows 控制代碼。 這不是控制代碼的複本,請勿釋放它。

Height

取得這個 Icon 的高度。

Size

取得這個 Icon 的大小。

Width

取得這個 Icon 的寬度。

方法

Clone()

複製 Icon,建立重複的影像。

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Dispose()

釋放這個 Icon 所使用的所有資源。

Equals(Object)

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

(繼承來源 Object)
ExtractAssociatedIcon(String)

傳回指定之檔案中所含影像的圖示表示。

ExtractIcon(String, Int32, Boolean)

從指定的 filePath 擷取指定的圖示。

ExtractIcon(String, Int32, Int32)

從指定的 filePath 擷取指定的圖示。

Finalize()

允許物件在記憶體回收進行回收之前,嘗試釋放資源並執行其他清除作業。

FromHandle(IntPtr)

從圖示的指定 Windows 控制代碼 (Icon) 建立 GDI+ HICON

GetHashCode()

做為預設雜湊函式。

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

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetType()

取得目前執行個體的 Type

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

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
Save(Stream)

將這個 Icon 儲存至指定的輸出 Stream

ToBitmap()

將這個 Icon 轉換成 GDI+ Bitmap

ToString()

取得描述 Icon 之人們可讀取的字串。

明確介面實作

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

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

適用於

另請參閱