ToolboxBitmapAttribute Classe

Definição

Permite especificar um ícone para representar um controle em um contêiner, como o Designer de Formulário do Microsoft Visual Studio.

public ref class ToolboxBitmapAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public class ToolboxBitmapAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type ToolboxBitmapAttribute = class
    inherit Attribute
Public Class ToolboxBitmapAttribute
Inherits Attribute
Herança
ToolboxBitmapAttribute
Atributos

Exemplos

O exemplo de código a seguir demonstra como usar a ToolboxBitmapAttribute classe para definir stop.bmp como o ícone de caixa de ferramentas para o StopSignControl. Este exemplo pressupõe a existência de um bitmap de 16 por 16 pixels chamado stop.bmp em c:\.

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

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

Comentários

Você pode aplicar um a um ToolboxBitmapAttribute controle para que contêineres, como Microsoft Designer de Formulários do Visual Studio, possam recuperar um ícone que representa o controle. O bitmap do ícone pode estar em um arquivo por si só ou inserido no assembly que contém o controle . O tamanho do bitmap que você insira no assembly do controle (ou armazene em um arquivo separado) deve ser 16 por 16. O GetImage método de um ToolboxBitmapAttribute objeto pode retornar a imagem pequena de 16 por 16 ou uma imagem grande de 32 por 32 que ele cria dimensionando a imagem pequena.

Se você quiser usar versões diferentes de seus ícones com versões diferentes do assembly, não precisará modificar o ToolboxBitmapAttribute para cada versão. Em vez disso, você pode declarar o assembly com um BitmapSuffixInSameAssemblyAttribute ou um BitmapSuffixInSatelliteAssemblyAttributee especificar um BitmapSuffix valor de configuração para cada versão do assembly. Nesse caso, um nome de arquivo indicado por um ToolboxBitmapAttribute é interpretado com o sufixo bitmap acrescentado.

Construtores

ToolboxBitmapAttribute(String)

Inicializa um novo objeto ToolboxBitmapAttribute com uma imagem de um arquivo especificado.

ToolboxBitmapAttribute(Type)

Inicializa um novo objeto ToolboxBitmapAttribute com base em um bitmap 16 x 16 que está inserido como um recurso em um assembly específico.

ToolboxBitmapAttribute(Type, String)

Inicializa um novo objeto ToolboxBitmapAttribute com base em um bitmap 16 por 16 que está inserido como um recurso em um assembly específico.

Campos

Default

Um objeto ToolboxBitmapAttribute que tem sua imagem pequena e sua imagem grande definidas como null.

Propriedades

TypeId

Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.

(Herdado de Attribute)

Métodos

Equals(Object)

Indica se o objeto especificado é um objeto ToolboxBitmapAttribute e se é idêntico a esse objeto ToolboxBitmapAttribute.

GetHashCode()

Obtém um código hash para esse objeto ToolboxBitmapAttribute.

GetImage(Object)

Obtém o Image pequeno associado a esse objeto ToolboxBitmapAttribute.

GetImage(Object, Boolean)

Obtém o Image pequeno ou grande associado a esse objeto ToolboxBitmapAttribute.

GetImage(Type)

Obtém o Image pequeno associado a esse objeto ToolboxBitmapAttribute.

GetImage(Type, Boolean)

Obtém o Image pequeno ou grande associado a esse objeto ToolboxBitmapAttribute.

GetImage(Type, String, Boolean)

Obtém o Image pequeno ou grande associado a esse objeto ToolboxBitmapAttribute.

GetImageFromResource(Type, String, Boolean)

Retorna um objeto Image com base em um recurso de bitmap inserido em um assembly.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.

(Herdado de Attribute)
Match(Object)

Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Implantações explícitas de interface

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.

(Herdado de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).

(Herdado de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornece acesso a propriedades e métodos expostos por um objeto.

(Herdado de Attribute)

Aplica-se a