Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


Icon Constructors

Definition

Initializes a new instance of the Icon class.

Overloads

Icon(Stream)

Initializes a new instance of the Icon class from the specified data stream.

Icon(String)

Initializes a new instance of the Icon class from the specified file name.

Icon(Icon, Size)

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)

Initializes a new instance of the Icon class of the specified size from the specified stream.

Icon(String, Size)

Initializes a new instance of the Icon class of the specified size from the specified file.

Icon(Type, String)

Initializes a new instance of the Icon class from a resource in the specified assembly.

Icon(Icon, Int32, Int32)

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)

Initializes a new instance of the Icon class from the specified data stream and with the specified width and height.

Icon(String, Int32, Int32)

Initializes a new instance of the Icon class with the specified width and height from the specified file.

Icon(Stream)

Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs

Initializes a new instance of the Icon class from the specified data stream.

C#
public Icon(System.IO.Stream stream);

Parameters

stream
Stream

The data stream from which to load the Icon.

Exceptions

The stream parameter is null.

Remarks

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 pixels x 16 pixels

  • 32 pixels x 32 pixels

  • 48 pixels x 48 pixels

This constructor returns the smallest image that is contained in the specified stream.

Applies to

.NET 10 (package-provided) és más verziók
Termék Verziók
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Icon(String)

Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs

Initializes a new instance of the Icon class from the specified file name.

C#
public Icon(string fileName);

Parameters

fileName
String

The file to load the Icon from.

Remarks

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 pixels x 16 pixels

  • 32 pixels x 32 pixels

  • 48 pixels x 48 pixels

This constructor returns the smallest image that is contained in the specified file.

Applies to

.NET 10 (package-provided) és más verziók
Termék Verziók
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Icon(Icon, Size)

Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs

Initializes a new instance of the Icon class and attempts to find a version of the icon that matches the requested size.

C#
public Icon(System.Drawing.Icon original, System.Drawing.Size size);

Parameters

original
Icon

The Icon from which to load the newly sized icon.

size
Size

A Size structure that specifies the height and width of the new Icon.

Exceptions

The original parameter is null.

Remarks

If a version cannot be found that exactly matches the size, the closest match is used. If the original parameter is an Icon that has a single size, this method only creates a duplicate icon. Use the stretching capabilities of the DrawImage method to resize the icon.

Applies to

.NET 10 (package-provided) és más verziók
Termék Verziók
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Icon(Stream, Size)

Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs

Initializes a new instance of the Icon class of the specified size from the specified stream.

C#
public Icon(System.IO.Stream stream, System.Drawing.Size size);

Parameters

stream
Stream

The stream that contains the icon data.

size
Size

The desired size of the icon.

Exceptions

The stream is null or does not contain image data.

Applies to

.NET 10 (package-provided) és más verziók
Termék Verziók
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Icon(String, Size)

Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs

Initializes a new instance of the Icon class of the specified size from the specified file.

C#
public Icon(string fileName, System.Drawing.Size size);

Parameters

fileName
String

The name and path to the file that contains the icon data.

size
Size

The desired size of the icon.

Exceptions

The fileName is null or does not contain image data.

Remarks

If the specified file does not contain an image that matches the desired size, the icon that has the closest size is returned.

The fileName should include the complete path if it is not in the current application directory.

Applies to

.NET 10 (package-provided) és más verziók
Termék Verziók
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Icon(Type, String)

Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs

Initializes a new instance of the Icon class from a resource in the specified assembly.

C#
public Icon(Type type, string resource);

Parameters

type
Type

A Type that specifies the assembly in which to look for the resource.

resource
String

The resource name to load.

Exceptions

An icon specified by resource cannot be found in the assembly that contains the specified type.

Examples

The following code example demonstrates how to use the Icon constructor. To run this example, paste the code into a Windows Form and handle the form's Paint event. Call the ConstructAnIconFromAType method from the Paint event handler, passing e as EventArgs.

C#
private void ConstructAnIconFromAType(PaintEventArgs e)
{

    Icon icon1 = new Icon(typeof(Control), "Error.ico");
    e.Graphics.DrawIcon(icon1, new Rectangle(10, 10, 50, 50));
}

Remarks

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. 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.

Applies to

.NET 10 (package-provided) és más verziók
Termék Verziók
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Icon(Icon, Int32, Int32)

Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs

Initializes a new instance of the Icon class and attempts to find a version of the icon that matches the requested size.

C#
public Icon(System.Drawing.Icon original, int width, int height);

Parameters

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.

Exceptions

The original parameter is null.

Examples

The following code example demonstrates how to use the ToBitmap method. This example is designed to be used with Windows Forms. Create a form and paste the following code into it. Call the IconToBitmap method in the form's Paint event handler, passing e as PaintEventArgs.

C#
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));
}

Remarks

If a version cannot be found that exactly matches the size, the closest match is used. If the original parameter is an Icon that has a single size, this method only creates a duplicate icon. Use the stretching capabilities of the DrawImage method to resize the icon.

Applies to

.NET 10 (package-provided) és más verziók
Termék Verziók
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Icon(Stream, Int32, Int32)

Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs

Initializes a new instance of the Icon class from the specified data stream and with the specified width and height.

C#
public Icon(System.IO.Stream stream, int width, int height);

Parameters

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.

Exceptions

The stream parameter is null.

Applies to

.NET 10 (package-provided) és más verziók
Termék Verziók
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Icon(String, Int32, Int32)

Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs
Source:
Icon.cs

Initializes a new instance of the Icon class with the specified width and height from the specified file.

C#
public Icon(string fileName, int width, int height);

Parameters

fileName
String

The name and path to the file that contains the Icon data.

width
Int32

The desired width of the Icon.

height
Int32

The desired height of the Icon.

Exceptions

The fileName is null or does not contain image data.

Remarks

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.

The fileName should include the complete path if it is not in the current application directory.

Applies to

.NET 10 (package-provided) és más verziók
Termék Verziók
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10