This documentation is archived and is not being maintained.

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)

'Declaration
<AttributeUsageAttribute(AttributeTargets.Class)> _
Public Class ToolboxBitmapAttribute _
	Inherits Attribute
'Usage
Dim instance As ToolboxBitmapAttribute

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
    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.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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: