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 窗体一起使用。This example is designed to be used with Windows Forms. 创建窗体并将以下代码粘贴到其中。Create a form and paste the following code into it. 在窗体的Paint事件处理程序中调用e PaintEventArgs方法,并IconToBitmap以形式传递。Call 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. 还可以Icon ToBitmap使用方法将转换为位图。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()

克隆 Icon,创建重复图像。Clones the Icon, creating a duplicate image.

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。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()

检索控制此实例的生存期策略的当前生存期服务对象。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 的浅表副本。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 的可读字符串。Gets a human-readable string that describes the Icon.

显式界面实现

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

使用序列化目标对象所需的数据填充 SerializationInfoPopulates a SerializationInfo with the data that is required to serialize the target object.

适用于

另请参阅