Export (0) Print
Expand All

Icon.Icon(Icon, Int32, Int32) Constructor

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

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

public Icon (
	Icon original,
	int width,
	int height
)
public Icon (
	Icon original, 
	int width, 
	int height
)
public function Icon (
	original : Icon, 
	width : int, 
	height : int
)
Not applicable.

Parameters

original

The icon to load the different size from.

width

The width of the new icon.

height

The height of the new icon.

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

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.

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 void IconToBitmap(PaintEventArgs e)
{
    // Construct an Icon.
    Icon icon1 = new Icon(SystemIcons.get_Exclamation(), 40, 40);

    // Call ToBitmap to convert it.
    Bitmap bmp = icon1.ToBitmap();

    // Draw the bitmap.
    e.get_Graphics().DrawImage(bmp, new Point(30, 30));
} //IconToBitmap

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft