Icon 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 Icon 类的新实例。
重载
| 名称 | 说明 |
|---|---|
| Icon(Stream) |
从指定的数据流初始化类的新实例 Icon 。 |
| Icon(String) |
从指定的文件名初始化类的新实例 Icon 。 |
| Icon(Icon, Size) |
初始化类的新实例 Icon ,并尝试查找与所请求大小匹配的图标版本。 |
| Icon(Stream, Size) |
从指定流初始化指定大小的类的新实例 Icon 。 |
| Icon(String, Size) |
从指定文件初始化指定大小的类的新实例 Icon 。 |
| Icon(Type, String) |
从指定程序集中的资源初始化类的新实例 Icon 。 |
| Icon(Icon, Int32, Int32) |
初始化类的新实例 Icon ,并尝试查找与所请求大小匹配的图标版本。 |
| Icon(Stream, Int32, Int32) |
使用指定的宽度和高度从指定的数据流初始化类的新实例 Icon 。 |
| Icon(String, Int32, Int32) |
使用指定文件的指定宽度和高度初始化类的新实例 Icon 。 |
Icon(Stream)
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
从指定的数据流初始化类的新实例 Icon 。
public:
Icon(System::IO::Stream ^ stream);
public Icon(System.IO.Stream stream);
new System.Drawing.Icon : System.IO.Stream -> System.Drawing.Icon
Public Sub New (stream As Stream)
参数
例外
参数 stream 为 null.
注解
图标资源可以包含多个图标图像。 一个图标文件可能包含多个大小和颜色深度的图像。 应用程序中使用的映像取决于操作系统和设置。 以下列表详细介绍了图标的典型大小:
16 像素 x 16 像素
32 像素 x 32 像素
48 像素 x 48 像素
此构造函数返回指定流中包含的最小图像。
适用于
Icon(String)
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
从指定的文件名初始化类的新实例 Icon 。
public:
Icon(System::String ^ fileName);
public Icon(string fileName);
new System.Drawing.Icon : string -> System.Drawing.Icon
Public Sub New (fileName As String)
参数
注解
图标资源可以包含多个图标图像。 一个图标文件可能包含多个大小和颜色深度的图像。 应用程序中使用的映像取决于操作系统和设置。 以下列表详细介绍了图标的典型大小:
16 像素 x 16 像素
32 像素 x 32 像素
48 像素 x 48 像素
此构造函数返回指定文件中包含的最小图像。
适用于
Icon(Icon, Size)
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
初始化类的新实例 Icon ,并尝试查找与所请求大小匹配的图标版本。
public:
Icon(System::Drawing::Icon ^ original, System::Drawing::Size size);
public Icon(System.Drawing.Icon original, System.Drawing.Size size);
new System.Drawing.Icon : System.Drawing.Icon * System.Drawing.Size -> System.Drawing.Icon
Public Sub New (original As Icon, size As Size)
参数
例外
参数 original 为 null.
注解
如果找不到与大小完全匹配的版本,则使用最接近的匹配项。
original如果参数是Icon具有单个大小的参数,此方法仅创建重复图标。 使用方法的 DrawImage 拉伸功能调整图标的大小。
适用于
Icon(Stream, Size)
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
从指定流初始化指定大小的类的新实例 Icon 。
public:
Icon(System::IO::Stream ^ stream, System::Drawing::Size size);
public Icon(System.IO.Stream stream, System.Drawing.Size size);
new System.Drawing.Icon : System.IO.Stream * System.Drawing.Size -> System.Drawing.Icon
Public Sub New (stream As Stream, size As Size)
参数
- stream
- Stream
包含图标数据的流。
- size
- Size
图标的所需大小。
例外
是streamnull或不包含图像数据。
适用于
Icon(String, Size)
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
从指定文件初始化指定大小的类的新实例 Icon 。
public:
Icon(System::String ^ fileName, System::Drawing::Size size);
public Icon(string fileName, System.Drawing.Size size);
new System.Drawing.Icon : string * System.Drawing.Size -> System.Drawing.Icon
Public Sub New (fileName As String, size As Size)
参数
- fileName
- String
包含图标数据的文件的名称和路径。
- size
- Size
图标的所需大小。
例外
是fileNamenull或不包含图像数据。
注解
如果指定的文件不包含与所需大小匹配的图像,则返回具有最接近大小的图标。
fileName如果路径不在当前应用程序目录中,则应包含完整路径。
适用于
Icon(Type, String)
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
从指定程序集中的资源初始化类的新实例 Icon 。
public:
Icon(Type ^ type, System::String ^ resource);
public Icon(Type type, string resource);
new System.Drawing.Icon : Type * string -> System.Drawing.Icon
Public Sub New (type As Type, resource As String)
参数
- resource
- String
要加载的资源名称。
例外
在包含指定对象的程序集中找不到由该 resource 图标指定的 type图标。
示例
下面的代码示例演示如何使用 Icon 构造函数。 若要运行此示例,请将代码粘贴到Windows窗体中,并处理表单的 Paint 事件。
ConstructAnIconFromAType从Paint事件处理程序调用该方法,并e作为 EventArgs.
private void ConstructAnIconFromAType(PaintEventArgs e)
{
Icon icon1 = new Icon(typeof(Control), "Error.ico");
e.Graphics.DrawIcon(icon1, new Rectangle(10, 10, 50, 50));
}
Private Sub ConstructAnIconFromAType(ByVal e As PaintEventArgs)
Dim icon1 As New Icon(GetType(Control), "Error.ico")
e.Graphics.DrawIcon(icon1, New Rectangle(10, 10, 50, 50))
End Sub
注解
此构造函数从包含参数指定的Icon类型的程序集中由参数指定的resource名称的资源创建一个type。
此构造函数将给定类型的命名空间与资源的字符串名称组合在一起,并在程序集清单中查找匹配项。 例如,可以将 Control 类型和 Error.ico 传递给此构造函数,并查找名为 System.Windows.Forms.Error.ico 的资源。
适用于
Icon(Icon, Int32, Int32)
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
初始化类的新实例 Icon ,并尝试查找与所请求大小匹配的图标版本。
public:
Icon(System::Drawing::Icon ^ original, int width, int height);
public Icon(System.Drawing.Icon original, int width, int height);
new System.Drawing.Icon : System.Drawing.Icon * int * int -> System.Drawing.Icon
Public Sub New (original As Icon, width As Integer, height As Integer)
参数
- original
- Icon
要从中加载不同大小的图标。
- width
- Int32
新图标的宽度。
- height
- Int32
新图标的高度。
例外
参数 original 为 null.
示例
下面的代码示例演示如何使用 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
注解
如果找不到与大小完全匹配的版本,则使用最接近的匹配项。
original如果参数是Icon具有单个大小的参数,此方法仅创建重复图标。 使用方法的 DrawImage 拉伸功能调整图标的大小。
适用于
Icon(Stream, Int32, Int32)
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
使用指定的宽度和高度从指定的数据流初始化类的新实例 Icon 。
public:
Icon(System::IO::Stream ^ stream, int width, int height);
public Icon(System.IO.Stream stream, int width, int height);
new System.Drawing.Icon : System.IO.Stream * int * int -> System.Drawing.Icon
Public Sub New (stream As Stream, width As Integer, height As Integer)
参数
- stream
- Stream
从中加载图标的数据流。
- width
- Int32
图标的宽度(以像素为单位)。
- height
- Int32
图标的高度(以像素为单位)。
例外
参数 stream 为 null.
适用于
Icon(String, Int32, Int32)
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
- Source:
- Icon.cs
使用指定文件的指定宽度和高度初始化类的新实例 Icon 。
public:
Icon(System::String ^ fileName, int width, int height);
public Icon(string fileName, int width, int height);
new System.Drawing.Icon : string * int * int -> System.Drawing.Icon
Public Sub New (fileName As String, width As Integer, height As Integer)
参数
例外
是fileNamenull或不包含图像数据。
注解
如果指定的文件不包含与所需高度和宽度匹配的图像,则返回具有最接近大小的图标。
fileName如果路径不在当前应用程序目录中,则应包含完整路径。