ToolboxBitmapAttribute Constructors

Definition

Initializes a new ToolboxBitmapAttribute object.

Overloads

ToolboxBitmapAttribute(String)

Initializes a new ToolboxBitmapAttribute object with an image from a specified file.

ToolboxBitmapAttribute(Type)

Initializes a new ToolboxBitmapAttribute object based on a 16 x 16 bitmap that is embedded as a resource in a specified assembly.

ToolboxBitmapAttribute(Type, String)

Initializes a new ToolboxBitmapAttribute object based on a 16 by 16 bitmap that is embedded as a resource in a specified assembly.

ToolboxBitmapAttribute(String)

Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs

Initializes a new ToolboxBitmapAttribute object with an image from a specified file.

C#
public ToolboxBitmapAttribute(string imageFile);

Parameters

imageFile
String

The name of a file that contains a 16 by 16 bitmap.

Examples

The following code example demonstrates how to use the ToolboxBitmapAttribute constructor 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:\.

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;
    }
}

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ToolboxBitmapAttribute(Type)

Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs

Initializes a new ToolboxBitmapAttribute object based on a 16 x 16 bitmap that is embedded as a resource in a specified assembly.

C#
public ToolboxBitmapAttribute(Type t);

Parameters

t
Type

A Type whose defining assembly is searched for the bitmap resource.

Examples

The following code example demonstrates how to use the ToolboxBitmapAttribute constructor to set the icon of the button control to the toolbox icon for a UserControl named StopSignControl3.

C#
[System.Drawing.ToolboxBitmap(typeof(System.Windows.Forms.Button))]
public class StopSignControl3:
    System.Windows.Forms.UserControl

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

    public StopSignControl3() : 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;
    }
}

Remarks

This constructor searches for an embedded resource in the assembly that defines the type specified by the t parameter. The constructor searches for a resource named namespace.classname.bmp, where namespace is the namespace containing the definition of the class specified by the t parameter. For example, if ControlA is in NamespaceA in AssemblyA.dll, then the constructor searches AssemblyA.dll for a resource named NamespaceA.ControlA.bmp.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ToolboxBitmapAttribute(Type, String)

Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs

Initializes a new ToolboxBitmapAttribute object based on a 16 by 16 bitmap that is embedded as a resource in a specified assembly.

C#
public ToolboxBitmapAttribute(Type t, string name);

Parameters

t
Type

A Type whose defining assembly is searched for the bitmap resource.

name
String

The name of the embedded bitmap resource.

Examples

'The following code example demonstrates how to use the ToolboxBitmapAttribute constructor to set StopSignControl2.bmp as a toolbox icon for the StopSignControl2. This example assumes the existence of a 16-by-16-pixel bitmap named StopSignControl2.bmp with its BuildAction property set to EmbeddedResource.

C#
[System.Drawing.ToolboxBitmap(typeof(StopSignControl2), "StopSignControl2.bmp")]
public class StopSignControl2:
    System.Windows.Forms.UserControl

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

    public StopSignControl2() : 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;
    }
}

Remarks

This constructor searches for an embedded resource in the assembly that defines the type specified by the t parameter. The constructor searches for a resource named namespace.name, where namespace is the namespace containing the definition of the class specified by the t parameter. For example, suppose that ControlA is a class in NamespaceA in AssemblyA.dll and that you passed "MyBitmap.bmp" to the name parameter. Then the constructor searches AssemblyA.dll for a resource named NamespaceA.MyBitmap.bmp.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10