ToolboxBitmapAttribute 类

这使您可以指定一个图标来表示容器的控件,例如 Microsoft Visual Studio 窗体设计器。

**命名空间:**System.Drawing
**程序集:**System.Drawing(在 system.drawing.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.Class)> _
Public Class ToolboxBitmapAttribute
    Inherits Attribute
用法
Dim instance As ToolboxBitmapAttribute
[AttributeUsageAttribute(AttributeTargets.Class)] 
public class ToolboxBitmapAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class)] 
public ref class ToolboxBitmapAttribute : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class) */ 
public class ToolboxBitmapAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class) 
public class ToolboxBitmapAttribute extends Attribute

备注

可以将 ToolboxBitmapAttribute 应用于一个控件,使容器(如 Microsoft Visual Studio Form Designer)能够检索到表示该控件的图标。图标的位图可以自成一个文件,也可以嵌入到包含该控件的程序集中。嵌入到控件的程序集中(或者存储在一个单独文件中)的位图大小应为 16 × 16。ToolboxBitmapAttribute 对象的 GetImage 方法可以返回一个小的 16 × 16 图像,或者返回一个通过将小图像放大而创建的 32 × 32 的大图像。

示例

下面的代码示例演示如何使用 ToolboxBitmapAttribute 类将 stop.bmp 设置为 StopSignControl 的工具箱图标。此示例假设在 c:\ 下存在名为 stop.bmp 的 16 × 16 像素位图。

<System.Drawing.ToolboxBitmap("c:\stop.bmp")> _
Public Class StopSignControl
    Inherits System.Windows.Forms.UserControl

    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Button1 As System.Windows.Forms.Button

    Public Sub New()
        MyBase.New()
        Me.Label1 = New System.Windows.Forms.Label
        Me.Button1 = New System.Windows.Forms.Button

        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", _
            12.0F, System.Drawing.FontStyle.Regular, _
            System.Drawing.GraphicsUnit.Point, CType(0, Byte))

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

        Me.Button1.Enabled = False
        Me.Button1.Location = New System.Drawing.Point(56, 88)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(40, 32)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "stop"

        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Label1)
        Me.Name = "StopSignControl"

    End Sub

    Private Sub StopSignControl_MouseEnter(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles MyBase.MouseEnter

        Label1.Text.ToUpper()
        Label1.Font = New System.Drawing.Font(Label1.Font.FontFamily, _
            14.0F, System.Drawing.FontStyle.Bold)
        Button1.Enabled = True
    End Sub

    Private Sub StopSignControl_MouseLeave(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles MyBase.MouseLeave

        Label1.Text.ToLower()
        Label1.Font = New System.Drawing.Font(Label1.Font.FontFamily, 12.0F, _
             System.Drawing.FontStyle.Regular)
        Button1.Enabled = False
    End Sub

End Class
[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;
    }

}
[ToolboxBitmap("c:\\stop.bmp")]
public ref class StopSignControl:
    public System::Windows::Forms::UserControl
{
private:
    Label^ label1;
private:
    Button^ button1;

public:
    StopSignControl() : UserControl()
    {
        this->label1 = gcnew System::Windows::Forms::Label();
        this->button1 = gcnew System::Windows::Forms::Button();

        this->label1->Font = gcnew 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 = 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 = System::Drawing::Point(56, 88);
        this->button1->Name = "Button1";
        this->button1->Size = 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";

        this->MouseEnter +=
            gcnew EventHandler(this, 
                &StopSignControl::StopSignControl_MouseEnter);
        this->MouseLeave +=
            gcnew EventHandler(this, 
                &StopSignControl::StopSignControl_MouseLeave);

    }

private:
    void StopSignControl_MouseEnter(Object^ sender,
        EventArgs^ e)
    {

        label1->Text = label1->Text->ToUpper();
        label1->Font = gcnew System::Drawing::Font(label1->Font->FontFamily,
            14.0F, FontStyle::Bold);
        button1->Enabled = true;
    }

private:
    void StopSignControl_MouseLeave(Object^ sender,
        EventArgs^ e)
    {

        label1->Text = label1->Text->ToLower();
        label1->Font = gcnew System::Drawing::Font(label1->Font->FontFamily,
            12.0F, 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

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

ToolboxBitmapAttribute 成员
System.Drawing 命名空间