0 out of 1 rated this helpful Rate this topic

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.

System.Object
  System.MarshalByRefObject
    System.Drawing.Icon

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.

  Name Description
Public method Icon(Stream) Initializes a new instance of the Icon class from the specified data stream.
Public method Icon(String) Initializes a new instance of the Icon class from the specified file name.
Public method 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.
Public method Icon(Stream, Size) Initializes a new instance of the Icon class of the specified size from the specified stream.
Public method Icon(String, Size) Initializes a new instance of the Icon class of the specified size from the specified file.
Public method Icon(Type, String) Initializes a new instance of the Icon class from a resource in the specified assembly.
Public method 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.
Public method Icon(Stream, Int32, Int32) Initializes a new instance of the Icon class from the specified data stream and with the specified width and height.
Public method Icon(String, Int32, Int32) Initializes a new instance of the Icon class with the specified width and height from the specified file.
Top
  Name Description
Public property Handle Gets the Windows handle for this Icon. This is not a copy of the handle; do not free it.
Public property Height Gets the height of this Icon.
Public property Size Gets the size of this Icon.
Public property Width Gets the width of this Icon.
Top
  Name Description
Public method Clone Clones the Icon, creating a duplicate image.
Public method CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public method Dispose Releases all resources used by this Icon.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public method Static member ExtractAssociatedIcon Returns an icon representation of an image that is contained in the specified file.
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Static member FromHandle Creates a GDI+ Icon from the specified Windows handle to an icon (HICON).
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public method Save Saves this Icon to the specified output Stream.
Public method ToBitmap Converts this Icon to a GDI+ Bitmap.
Public method ToString Gets a human-readable string that describes the Icon. (Overrides Object.ToString.)
Top
  Name Description
Explicit interface implemetation Private method ISerializable.GetObjectData Populates 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, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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.
Did you find this helpful?
(2000 characters remaining)
Community Content Add
Annotations FAQ
Missleading example.
As far as I can see the example code does not work as intended.

Icon icon1 = new Icon(SystemIcons.Exclamation, 40, 40);

Will result in an exclamation icon of size 32x32.

(WindowsXP, .NET 3.5)
  • 11/22/2011
  • Krx