Export (0) Print
Expand All

Icon Constructor (Type, String)

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

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

public Icon(
	Type type,
	string resource
)

Parameters

type
Type: System.Type

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

resource
Type: System.String

The resource name to load.

ExceptionCondition
ArgumentException

An icon specified by resource cannot be found in the assembly that contains the specified 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. 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.

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.

private void ConstructAnIconFromAType(PaintEventArgs e)
{

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

}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft