Export (0) Print
Expand All

Icon Class

Represents a Windows icon, which is a small bitmap image that is used to represent an object. Icons can be thought of as transparent bitmaps, although their size is determined by the system.

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

[SerializableAttribute]
[TypeConverterAttribute(typeof(IconConverter))]
public sealed class Icon : MarshalByRefObject, ISerializable, 
	ICloneable, IDisposable

The Icon type exposes the following members.

  NameDescription
Public methodIcon(Stream)Initializes a new instance of the Icon class from the specified data stream.
Public methodIcon(String)Initializes a new instance of the Icon class from the specified file name.
Public methodIcon(Icon, Size)Initializes a new instance of the Icon class and attempts to find a version of the icon that matches the requested size.
Public methodIcon(Stream, Size)Initializes a new instance of the Icon class of the specified size from the specified stream.
Public methodIcon(String, Size)Initializes a new instance of the Icon class of the specified size from the specified file.
Public methodIcon(Type, String)Initializes a new instance of the Icon class from a resource in the specified assembly.
Public methodIcon(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.
Public methodIcon(Stream, Int32, Int32)Initializes a new instance of the Icon class from the specified data stream and with the specified width and height.
Public methodIcon(String, Int32, Int32)Initializes a new instance of the Icon class with the specified width and height from the specified file.
Top

  NameDescription
Public propertyHandleGets the Windows handle for this Icon. This is not a copy of the handle; do not free it.
Public propertyHeightGets the height of this Icon.
Public propertySizeGets the size of this Icon.
Public propertyWidthGets the width of this Icon.
Top

  NameDescription
Public methodCloneClones the Icon, creating a duplicate image.
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodDisposeReleases all resources used by this Icon.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodStatic memberExtractAssociatedIconReturns an icon representation of an image that is contained in the specified file.
Public methodStatic memberFromHandleCreates a GDI+ Icon from the specified Windows handle to an icon (HICON).
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodSaveSaves this Icon to the specified output Stream.
Public methodToBitmapConverts this Icon to a GDI+ Bitmap.
Public methodToStringGets a human-readable string that describes the Icon. (Overrides Object.ToString().)
Top

  NameDescription
Explicit interface implemetationPrivate methodISerializable.GetObjectDataPopulates a SerializationInfo with the data that is required to serialize the target object.
Top

You can construct Icon objects from files, streams, or embedded resources. For a list of constructors, see Icon. You can also convert an Icon to a bitmap by using the ToBitmap method.

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

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

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft