Icon 類別

定義

表示 Windows 圖示,這個圖示為用來表示物件的小型點陣圖影像。Represents a Windows icon, which is a small bitmap image that is used to represent an object. 雖然圖示的大小是由系統決定,但是圖示仍然可以視為透明的點陣圖。Icons can be thought of as transparent bitmaps, although their size is determined by the system.

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

範例

下列程式碼範例會示範如何使用 ToBitmap 方法。The following code example demonstrates how to use the ToBitmap method. 這個範例是設計來與 Windows Forms 搭配使用。This example is designed to be used with Windows Forms. 建立表單,並在其中貼上下列程式碼。Create a form and paste the following code into it. 在表單的Paint事件處理常式中呼叫e PaintEventArgs方法,傳遞做為。 IconToBitmapCall the IconToBitmap method in the form's Paint event handler, passing e as 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檔案、資料流程或內嵌資源來建立物件。You can construct Icon objects from files, streams, or embedded resources. 如需函式的清單, Icon請參閱。For a list of constructors, see Icon. 您也可以ToBitmap使用方法Icon ,將轉換成點陣圖。You can also convert an Icon to a bitmap by using the ToBitmap method.

圖示資源可以包含多個圖示影像。An icon resource can contain multiple icon images. 一個圖示檔可能包含數種大小和色彩深度的影像。One icon file may contain images in several sizes and color depths. 應用程式中使用的映射取決於作業系統和設定。The image that is used in an application depends on the operating system and settings. 下列清單詳細說明圖示的一般大小:The following list details the typical sizes for an icon:

  • 16圖元 x 16 圖元16 pixels x 16 pixels

  • 32圖元 x 32 圖元32 pixels x 32 pixels

  • 48圖元 x 48 圖元48 pixels x 48 pixels

建構函式

Icon(Icon, Int32, Int32)

初始化 Icon 類別的新執行個體,並嘗試尋找符合所要求大小的圖示版本。Initializes a new instance of the Icon class and attempts to find a version of the icon that matches the requested size.

Icon(Icon, Size)

初始化 Icon 類別的新執行個體,並嘗試尋找符合所要求大小的圖示版本。Initializes a new instance of the Icon class and attempts to find a version of the icon that matches the requested size.

Icon(Stream)

從指定的資料流,初始化 Icon 類別的新執行個體。Initializes a new instance of the Icon class from the specified data stream.

Icon(Stream, Int32, Int32)

使用指定的寬度和高度,從指定的資料流初始化 Icon 類別的新執行個體。Initializes a new instance of the Icon class from the specified data stream and with the specified width and height.

Icon(Stream, Size)

從指定的資料流,以指定之大小初始化 Icon 類別的新執行個體。Initializes a new instance of the Icon class of the specified size from the specified stream.

Icon(String)

從指定的檔案名稱初始化 Icon 類別的新執行個體。Initializes a new instance of the Icon class from the specified file name.

Icon(String, Int32, Int32)

使用來自指定檔案的指定寬度和高度,初始化 Icon 類別的新執行個體。Initializes a new instance of the Icon class with the specified width and height from the specified file.

Icon(String, Size)

從指定的資料流,以指定之大小初始化 Icon 類別的新執行個體。Initializes a new instance of the Icon class of the specified size from the specified file.

Icon(Type, String)

從指定的組件中的資源,初始化 Icon 類別的新執行個體。Initializes a new instance of the Icon class from a resource in the specified assembly.

屬性

Handle

取得這個 Icon 的 Windows 控制代碼。Gets the Windows handle for this Icon. 這不是控制代碼的複本,請勿釋放它。This is not a copy of the handle; do not free it.

Height

取得這個 Icon 的高度。Gets the height of this Icon.

Size

取得這個 Icon 的大小。Gets the size of this Icon.

Width

取得這個 Icon 的寬度。Gets the width of this Icon.

方法

Clone()

複製 (Clone) Icon,建立重複的影像。Clones the Icon, creating a duplicate image.

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
Dispose()

釋放這個 Icon 所使用的所有資源。Releases all resources used by this Icon.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
ExtractAssociatedIcon(String)

傳回指定之檔案中所含影像的圖示表示。Returns an icon representation of an image that is contained in the specified file.

Finalize()

允許物件在記憶體回收進行回收之前,嘗試釋放資源並執行其他清除作業。Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

FromHandle(IntPtr)

從圖示的指定 Windows 控制代碼 (HICON) 建立 GDI+ IconCreates a GDI+ Icon from the specified Windows handle to an icon (HICON).

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 MarshalByRefObject)
Save(Stream)

將這個 Icon 儲存至指定的輸出 StreamSaves this Icon to the specified output Stream.

ToBitmap()

將這個 Icon 轉換成 GDI+ BitmapConverts this Icon to a GDI+ Bitmap.

ToString()

取得描述 Icon 之人們可讀取的 (Human-Readable) 字串。Gets a human-readable string that describes the Icon.

明確介面實作

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

SerializationInfo 中填入將目標物件序列化時所需的資料。Populates a SerializationInfo with the data that is required to serialize the target object.

適用於

另請參閱