Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ToolboxBitmapAttribute Class
Collapse the table of content
Expand the table of content

ToolboxBitmapAttribute Class

Allows you to specify an icon to represent a control in a container, such as the Microsoft Visual Studio Form Designer.


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

public class ToolboxBitmapAttribute : Attribute

The ToolboxBitmapAttribute type exposes the following members.

Public methodToolboxBitmapAttribute(String)Initializes a new ToolboxBitmapAttribute object with an image from a specified file.
Public methodToolboxBitmapAttribute(Type)Initializes a new ToolboxBitmapAttribute object based on a 16 x 16 bitmap that is embedded as a resource in a specified assembly.
Public methodToolboxBitmapAttribute(Type, String)Initializes a new ToolboxBitmapAttribute object based on a 16 by 16 bitmap that is embedded as a resource in a specified assembly.

Public propertyTypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)

Public methodEqualsIndicates whether the specified object is a ToolboxBitmapAttribute object and is identical to this ToolboxBitmapAttribute object. (Overrides Attribute.Equals(Object).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeGets a hash code for this ToolboxBitmapAttribute object. (Overrides Attribute.GetHashCode().)
Public methodGetImage(Object)Gets the small Image associated with this ToolboxBitmapAttribute object.
Public methodGetImage(Type)Gets the small Image associated with this ToolboxBitmapAttribute object.
Public methodGetImage(Object, Boolean)Gets the small or large Image associated with this ToolboxBitmapAttribute object.
Public methodGetImage(Type, Boolean)Gets the small or large Image associated with this ToolboxBitmapAttribute object.
Public methodGetImage(Type, String, Boolean)Gets the small or large Image associated with this ToolboxBitmapAttribute object.
Public methodStatic memberGetImageFromResourceReturns an Image object based on a bitmap resource that is embedded in an assembly.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIsDefaultAttributeWhen overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)
Public methodMatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Public fieldStatic memberDefaultA ToolboxBitmapAttribute object that has its small image and its large image set to null.

Explicit interface implemetationPrivate method_Attribute.GetIDsOfNamesMaps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetationPrivate method_Attribute.GetTypeInfoRetrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)
Explicit interface implemetationPrivate method_Attribute.GetTypeInfoCountRetrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetationPrivate method_Attribute.InvokeProvides access to properties and methods exposed by an object. (Inherited from Attribute.)

You can apply a ToolboxBitmapAttribute to a control so that containers, such as Microsoft Visual Studio Form Designer, can retrieve an icon that represents the control. The bitmap for the icon can be in a file by itself or embedded in the assembly that contains the control. The size of the bitmap that you embed in the control's assembly (or store in a separate file) should be 16 by 16. The GetImage method of a ToolboxBitmapAttribute object can return the small 16 by 16 image or a large 32 by 32 image that it creates by scaling the small image.

If you want to use different versions of your icons with different versions of your assembly, you do not have to modify the ToolboxBitmapAttribute for each version. Instead, you can declare the assembly with a BitmapSuffixInSameAssemblyAttribute or a BitmapSuffixInSatelliteAssemblyAttribute, and specify a BitmapSuffix configuration value for each assembly version. In this case, a file name indicated by a ToolboxBitmapAttribute is interpreted with the bitmap suffix appended.

The following code example demonstrates how to use the ToolboxBitmapAttribute class to set stop.bmp as the toolbox icon for the StopSignControl. This example assumes the existence of a 16-by-16-pixel bitmap named stop.bmp at c:\.

public class StopSignControl:

    internal System.Windows.Forms.Label Label1;
    internal System.Windows.Forms.Button Button1;

    public StopSignControl() : base()
        this.Label1 = new System.Windows.Forms.Label();
        this.Button1 = new System.Windows.Forms.Button();

        this.Label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) 0));

        this.Label1.ForeColor = System.Drawing.Color.Red;
        this.Label1.Location = new System.Drawing.Point(24, 56);
        this.Label1.Name = "Label1";
        this.Label1.TabIndex = 0;
        this.Label1.Text = "Stop!";
        this.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

        this.Button1.Enabled = false;
        this.Button1.Location = new System.Drawing.Point(56, 88);
        this.Button1.Name = "Button1";
        this.Button1.Size = new System.Drawing.Size(40, 32);
        this.Button1.TabIndex = 1;
        this.Button1.Text = "stop";

        this.Name = "StopSignControl";


    private void StopSignControl_MouseEnter(object sender, System.EventArgs e)

        Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 14.0F, 
        Button1.Enabled = true;

    private void StopSignControl_MouseLeave(object sender, System.EventArgs e)

        Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 12.0F, 
        Button1.Enabled = false;


.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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