Icon Icon Icon Icon Class

Definition

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.

public ref class Icon sealed : MarshalByRefObject, ICloneable, IDisposable, System::Runtime::Serialization::ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))]
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public sealed class Icon : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
type Icon = class
    inherit MarshalByRefObject
    interface ISerializable
    interface ICloneable
    interface IDisposable
Public NotInheritable Class Icon
Inherits MarshalByRefObject
Implements ICloneable, IDisposable, ISerializable
Inheritance
Attributes
Implements

Examples

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.
      System::Drawing::Icon^ icon1 = gcnew System::Drawing::Icon( SystemIcons::Exclamation,40,40 );

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

      // Draw the bitmap.
      e->Graphics->DrawImage( bmp, Point(30,30) );
   }
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 Sub IconToBitmap(ByVal e As PaintEventArgs)

    ' Construct an Icon.
    Dim icon1 As New Icon(SystemIcons.Exclamation, 40, 40)

    ' Call ToBitmap to convert it.
    Dim bmp As Bitmap = icon1.ToBitmap()

    ' Draw the bitmap.
    e.Graphics.DrawImage(bmp, New Point(30, 30))
End Sub

Remarks

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

Constructors

Icon(Icon, Int32, Int32) Icon(Icon, Int32, Int32) Icon(Icon, Int32, Int32) 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.

Icon(Icon, Size) Icon(Icon, Size) Icon(Icon, Size) 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.

Icon(Stream) Icon(Stream) Icon(Stream) Icon(Stream)

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

Icon(Stream, Int32, Int32) Icon(Stream, Int32, Int32) Icon(Stream, Int32, Int32) Icon(Stream, Int32, Int32)

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

Icon(Stream, Size) Icon(Stream, Size) Icon(Stream, Size) Icon(Stream, Size)

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

Icon(String) Icon(String) Icon(String) Icon(String)

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

Icon(String, Int32, Int32) Icon(String, Int32, Int32) Icon(String, Int32, Int32) Icon(String, Int32, Int32)

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

Icon(String, Size) Icon(String, Size) Icon(String, Size) Icon(String, Size)

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

Icon(Type, String) Icon(Type, String) Icon(Type, String) Icon(Type, String)

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

Properties

Handle Handle Handle Handle

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

Height Height Height Height

Gets the height of this Icon.

Size Size Size Size

Gets the size of this Icon.

Width Width Width Width

Gets the width of this Icon.

Methods

Clone() Clone() Clone() Clone()

Clones the Icon, creating a duplicate image.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(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)
Dispose() Dispose() Dispose() Dispose()

Releases all resources used by this Icon.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
ExtractAssociatedIcon(String) ExtractAssociatedIcon(String) ExtractAssociatedIcon(String) ExtractAssociatedIcon(String)

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

Finalize() Finalize() Finalize() Finalize()

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

FromHandle(IntPtr) FromHandle(IntPtr) FromHandle(IntPtr) FromHandle(IntPtr)

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

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
Save(Stream) Save(Stream) Save(Stream) Save(Stream)

Saves this Icon to the specified output Stream.

ToBitmap() ToBitmap() ToBitmap() ToBitmap()

Converts this Icon to a GDI+ Bitmap.

ToString() ToString() ToString() ToString()

Gets a human-readable string that describes the Icon.

Explicit Interface Implementations

ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext)

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

Applies to

See also