Icon 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示一个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在窗体的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。 还可以使用Icon该方法将位ToBitmap图转换为位图。
注释
在 .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, 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 。 |
属性
| 名称 | 说明 |
|---|---|
| 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) |
从给定 |
| ExtractIcon(String, Int32, Int32) |
从给定 |
| Finalize() |
允许对象在垃圾回收回收资源之前尝试释放资源并执行其他清理操作。 |
| FromHandle(IntPtr) |
从指定的Windows句柄创建 GDI+ Icon图标( |
| GetHashCode() |
用作默认哈希函数。 (继承自 Object) |
| GetLifetimeService() |
已过时.
检索控制此实例的生存期策略的当前生存期服务对象。 (继承自 MarshalByRefObject) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| InitializeLifetimeService() |
已过时.
获取生存期服务对象来控制此实例的生存期策略。 (继承自 MarshalByRefObject) |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| MemberwiseClone(Boolean) |
创建当前 MarshalByRefObject 对象的浅表副本。 (继承自 MarshalByRefObject) |
| Save(Stream) | |
| ToBitmap() | |
| ToString() |
获取描述 . Icon. |
显式接口实现
| 名称 | 说明 |
|---|---|
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
使用 SerializationInfo 序列化目标对象所需的数据填充数据。 |