Icon 构造函数
定义
重载
Icon(Stream) |
从指定的数据流初始化 Icon 类的新实例。Initializes a new instance of the Icon class from the specified data stream. |
Icon(String) |
从指定的文件名初始化 Icon 类的新实例。Initializes a new instance of the Icon class from the specified file name. |
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, Size) |
从指定的流初始化 Icon 类的指定大小的新实例。Initializes a new instance of the Icon class of the specified size from the specified stream. |
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. |
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(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(String, Int32, Int32) |
使用指定文件中的指定宽度和高度初始化 Icon 类的一个新实例。Initializes a new instance of the Icon class with the specified width and height from the specified file. |
Icon(Stream)
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
。The stream
parameter is null
.
注解
图标资源可以包含多个图标图像。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
此构造函数返回指定流中包含的最小图像。This constructor returns the smallest image that is contained in the specified stream.
适用于
Icon(String)
public:
Icon(System::String ^ fileName);
public Icon (string fileName);
new System.Drawing.Icon : string -> System.Drawing.Icon
Public Sub New (fileName As String)
参数
注解
图标资源可以包含多个图标图像。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
此构造函数返回指定文件中包含的最小图像。This constructor returns the smallest image that is contained in the specified file.
适用于
Icon(Icon, Size)
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)
参数
- size
- Size
用于指定新 Icon 的高度和宽度的 Size 结构。A Size structure that specifies the height and width of the new Icon.
例外
original
参数为 null
。The original
parameter is null
.
注解
如果找不到与大小完全匹配的版本,将使用最接近的匹配项。If a version cannot be found that exactly matches the size, the closest match is used. 如果 original
参数是一个 Icon 具有单个大小的,则此方法仅创建一个重复的图标。If the original
parameter is an Icon that has a single size, this method only creates a duplicate icon. 使用方法的拉伸功能 DrawImage 调整图标大小。Use the stretching capabilities of the DrawImage method to resize the icon.
适用于
Icon(Stream, Size)
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
包含图标数据的流。The stream that contains the icon data.
- size
- Size
所需的图标大小。The desired size of the icon.
例外
stream
为 null
或不包含图像数据。The stream
is null
or does not contain image data.
适用于
Icon(String, Size)
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
包含图标数据的文件的名称和路径。The name and path to the file that contains the icon data.
- size
- Size
所需的图标大小。The desired size of the icon.
例外
string
为 null
或不包含图像数据。The string
is null
or does not contain image data.
注解
如果指定的文件不包含匹配所需大小的图像,则返回具有最接近大小的图标。If the specified file does not contain an image that matches the desired size, the icon that has the closest size is returned.
fileName
如果不在当前应用程序目录中,则应包含完整的路径。The fileName
should include the complete path if it is not in the current application directory.
适用于
Icon(Type, String)
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
要加载的资源的名称。The resource name to load.
例外
由 resource
指定的图标无法在包含指定 type
的程序集中找到。An icon specified by resource
cannot be found in the assembly that contains the specified type
.
示例
下面的代码示例演示如何使用 Icon 构造函数。The following code example demonstrates how to use the Icon constructor. 若要运行此示例,请将代码粘贴到 Windows 窗体中,然后处理窗体的 Paint 事件。To run this example, paste the code into a Windows Form and handle the form's Paint event. ConstructAnIconFromAType
从 Paint 事件处理程序调用方法,并 e
以形式传递 EventArgs 。Call the ConstructAnIconFromAType
method from the Paint event handler, passing e
as 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
。This constructor creates an Icon from a resource with the name specified by the resource
parameter in the assembly that contains the type specified by the type
parameter.
此构造函数将给定类型的命名空间与资源的字符串名称组合在一起,并在程序集清单中查找匹配项。This constructor combines the namespace of the given type together with the string name of the resource and looks for a match in the assembly manifest. 例如,可以将 Control 类型和传递 Error.ico
到此构造函数,并查找名为的资源 System.Windows.Forms.Error.ico
。For example you can pass in the Control type and Error.ico
to this constructor, and it looks for a resource that is named System.Windows.Forms.Error.ico
.
适用于
Icon(Icon, Int32, Int32)
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
要从其中加载不同大小的图标。The icon to load the different size from.
- width
- Int32
新图标的宽度。The width of the new icon.
- height
- Int32
新图标的高度。The height of the new icon.
例外
original
参数为 null
。The original
parameter is null
.
示例
下面的代码示例演示如何使用 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. IconToBitmap
在窗体的 Paint 事件处理程序中调用方法,并 e
以形式传递 PaintEventArgs 。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
注解
如果找不到与大小完全匹配的版本,将使用最接近的匹配项。If a version cannot be found that exactly matches the size, the closest match is used. 如果 original
参数是一个 Icon 具有单个大小的,则此方法仅创建一个重复的图标。If the original
parameter is an Icon that has a single size, this method only creates a duplicate icon. 使用方法的拉伸功能 DrawImage 调整图标大小。Use the stretching capabilities of the DrawImage method to resize the icon.
适用于
Icon(Stream, Int32, Int32)
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
从其中加载图标的数据流。The data stream from which to load the icon.
- width
- Int32
图标的宽度(以像素为单位)。The width, in pixels, of the icon.
- height
- Int32
图标的高度(以像素为单位)。The height, in pixels, of the icon.
例外
stream
参数为 null
。The stream
parameter is null
.
适用于
Icon(String, Int32, Int32)
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)
参数
例外
string
为 null
或不包含图像数据。The string
is null
or does not contain image data.
注解
如果指定的文件不包含匹配所需高度和宽度的图像,则返回具有最接近大小的图标。If the specified file does not contain an image that matches the desired height and width, the icon that has the closest size is returned.
fileName
如果不在当前应用程序目录中,则应包含完整的路径。The fileName
should include the complete path if it is not in the current application directory.