Export (0) Print
Expand All

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)

[AttributeUsageAttribute(AttributeTargets.Class)] 
public class ToolboxBitmapAttribute : Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class) */ 
public class ToolboxBitmapAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class) 
public class ToolboxBitmapAttribute extends Attribute
Not applicable.

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.

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:\.

[System.Drawing.ToolboxBitmap("c:\\stop.bmp")]
public class StopSignControl:
    System.Windows.Forms.UserControl

{
    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.Controls.Add(this.Button1);
        this.Controls.Add(this.Label1);
        this.Name = "StopSignControl";

    }

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

        Label1.Text.ToUpper();
        Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 14.0F, 
	    System.Drawing.FontStyle.Bold);
        Button1.Enabled = true;
    }

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

        Label1.Text.ToLower();
        Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 12.0F, 
	    System.Drawing.FontStyle.Regular);
        Button1.Enabled = false;
    }

}

/** @attribute System.Drawing.ToolboxBitmap("c:\\stop.bmp")
 */
public class StopSignControl extends System.Windows.Forms.UserControl
{
    System.Windows.Forms.Label label1;
    System.Windows.Forms.Button button1;

    public StopSignControl()
    {
        this.label1 = new System.Windows.Forms.Label();
        this.button1 = new System.Windows.Forms.Button();

        this.label1.set_Font(new System.Drawing.Font("Microsoft Sans Serif", 
            12, System.Drawing.FontStyle.Regular, 
            System.Drawing.GraphicsUnit.Point, (ubyte)0));

        this.label1.set_ForeColor(System.Drawing.Color.get_Red());
        this.label1.set_Location(new System.Drawing.Point(24, 56));
        this.label1.set_Name("label1");
        this.label1.set_TabIndex(0);
        this.label1.set_Text("Stop!");
        this.label1.set_TextAlign(System.Drawing.ContentAlignment.MiddleCenter);

        this.button1.set_Enabled(false);
        this.button1.set_Location(new System.Drawing.Point(56, 88));
        this.button1.set_Name("button1");
        this.button1.set_Size(new System.Drawing.Size(40, 32));
        this.button1.set_TabIndex(1);
        this.button1.set_Text("stop");

        this.get_Controls().Add(this.button1);
        this.get_Controls().Add(this.label1);
        this.set_Name("StopSignControl");
    } //StopSignControl

    private void StopSignControl_MouseEnter(Object sender, System.EventArgs e)
    {
        label1.set_Text(label1.get_Text().ToUpper());
        label1.set_Font(new Font(label1.get_Font().get_FontFamily(), 14, 
            FontStyle.Bold));
        button1.set_Enabled(true);
    } //StopSignControl_MouseEnter

    private void StopSignControl_MouseLeave(Object sender, System.EventArgs e)
    {
        label1.set_Text(label1.get_Text().ToLower());
        label1.set_Font(new Font(label1.get_Font().get_FontFamily(), 12, 
            System.Drawing.FontStyle.Regular));
        button1.set_Enabled(false);
    } //StopSignControl_MouseLeave
} //StopSignControl

System.Object
   System.Attribute
    System.Drawing.ToolboxBitmapAttribute

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

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft