Breyta

Deila með


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.Serializable]
public sealed class Icon : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(false)]
public sealed class Icon : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))]
public sealed class Icon : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter("System.Drawing.IconConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")]
public sealed class Icon : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))>]
[<System.Serializable>]
type Icon = class
    inherit MarshalByRefObject
    interface ICloneable
    interface IDisposable
    interface ISerializable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(false)>]
type Icon = class
    inherit MarshalByRefObject
    interface ISerializable
    interface ICloneable
    interface IDisposable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))>]
[<System.Serializable>]
type Icon = class
    inherit MarshalByRefObject
    interface ISerializable
    interface ICloneable
    interface IDisposable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.IconConverter))>]
type Icon = class
    inherit MarshalByRefObject
    interface ICloneable
    interface IDisposable
    interface ISerializable
[<System.ComponentModel.TypeConverter("System.Drawing.IconConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")>]
type Icon = class
    inherit MarshalByRefObject
    interface ICloneable
    interface IDisposable
    interface ISerializable
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.

Note

In .NET 6 and later versions, the System.Drawing.Common package, which includes this type, is only supported on Windows operating systems. Use of this type in cross-platform apps causes compile-time warnings and run-time exceptions. For more information, see System.Drawing.Common only supported on Windows.

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)

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)

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

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)

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

Icon(Stream)

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

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)

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

Icon(String)

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

Icon(Type, String)

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

Properties

Handle

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

Height

Gets the height of this Icon.

Size

Gets the size of this Icon.

Width

Gets the width of this Icon.

Methods

Clone()

Clones the Icon, creating a duplicate image.

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()

Releases all resources used by this Icon.

Equals(Object)

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

(Inherited from Object)
ExtractAssociatedIcon(String)

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

ExtractIcon(String, Int32, Boolean)

Extracts a specified icon from the given filePath.

ExtractIcon(String, Int32, Int32)

Extracts a specified icon from the given filePath.

Finalize()

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

FromHandle(IntPtr)

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

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

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

(Inherited from MarshalByRefObject)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

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

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
Save(Stream)

Saves this Icon to the specified output Stream.

ToBitmap()

Converts this Icon to a GDI+ Bitmap.

ToString()

Gets a human-readable string that describes the Icon.

Explicit Interface Implementations

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

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

Applies to

See also