Icon Class

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

NameDescription
System_CAPS_pubmethodIcon(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.

System_CAPS_pubmethodIcon(Icon, Size)

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

System_CAPS_pubmethodIcon(Stream)

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

System_CAPS_pubmethodIcon(Stream, Int32, Int32)

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

System_CAPS_pubmethodIcon(Stream, Size)

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

System_CAPS_pubmethodIcon(String)

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

System_CAPS_pubmethodIcon(String, Int32, Int32)

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

System_CAPS_pubmethodIcon(String, Size)

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

System_CAPS_pubmethodIcon(Type, String)

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

NameDescription
System_CAPS_pubpropertyHandle

Gets the Windows handle for this Icon. This is not a copy of the handle; do not free it.

System_CAPS_pubpropertyHeight

Gets the height of this Icon.

System_CAPS_pubpropertySize

Gets the size of this Icon.

System_CAPS_pubpropertyWidth

Gets the width of this Icon.

NameDescription
System_CAPS_pubmethodClone()

Clones the Icon, creating a duplicate image.

System_CAPS_pubmethodCreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodDispose()

Releases all resources used by this Icon.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodSystem_CAPS_staticExtractAssociatedIcon(String)

Returns an icon representation of an image that is contained in the specified file.

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Overrides Object.Finalize().)

System_CAPS_pubmethodSystem_CAPS_staticFromHandle(IntPtr)

Creates a GDI+ Icon from the specified Windows handle to an icon (HICON).

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodInitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodSave(Stream)

Saves this Icon to the specified output Stream.

System_CAPS_pubmethodToBitmap()

Converts this Icon to a GDI+ Bitmap.

System_CAPS_pubmethodToString()

Gets a human-readable string that describes the Icon.(Overrides Object.ToString().)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodISerializable.GetObjectData(SerializationInfo, StreamingContext)

Populates a SerializationInfo with the data that is required to serialize the target object.

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
Available since 1.1

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

Return to top
Show:
© 2016 Microsoft