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 窗体 一起使用。 创建窗体并将以下代码粘贴到其中。 IconToBitmap在窗体的Paint事件处理程序中调用 方法,作为 ePaintEventArgs传递。

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 及更高版本中, System.Drawing.Common 包(包括此类型)仅在 Windows 操作系统上受支持。 在跨平台应用中使用此类型会导致编译时警告和运行时异常。 有关详细信息,请参阅 仅在 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)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。

(继承自 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()
已过时.

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 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

适用于

另请参阅