Export (0) Print
Expand All

How to: Provide a Toolbox Bitmap for a Control 

If you want to have a special icon for your control appear in the Toolbox, you can specify a particular image by using the ToolboxBitmapAttribute. This class is an attribute, a special kind of class you can attach to other classes. For more information about attributes, see Attributes Overview in Visual Basic for Visual Basic and Attributes (C# Programming Guide) for Visual C#.

Using the ToolboxBitmapAttribute, you can specify a string that indicates the path and file name for a 16 by 16 pixel bitmap. This bitmap then appears next to your control when added to the Toolbox. You can also specify a Type, in which case the bitmap associated with that type is loaded. If you specify both a Type and a string, the control searches for an image resource with the name specified by the string parameter in the assembly containing the type specified by the Type parameter.

To specify a Toolbox bitmap for your control

  • Add the ToolboxBitmapAttribute to the class declaration of your control before the Class keyword for Visual Basic, and above the class declaration for Visual C#.

    ' Specifies the bitmap associated with the Button type.
    <ToolboxBitmap(GetType(Button))> Class MyControl1
    ' Specifies a bitmap file.
    End Class
    <ToolboxBitmap("C:\Documents and Settings\Joe\MyPics\myImage.bmp")> _
       Class MyControl2
    End Class
    ' Specifies a type that indicates the assembly to search, and the name 
    ' of an image resource to look for.
    <ToolboxBitmap(GetType(MyControl), "MyControlBitmap")> Class MyControl
    End Class
    

    // Specifies the bitmap associated with the Button type.
    [ToolboxBitmap(typeof(Button))]
    class MyControl1 : UserControl
    {
    }
    // Specifies a bitmap file.
    [ToolboxBitmap(@"C:\Documents and Settings\Joe\MyPics\myImage.bmp")]
    class MyControl2 : UserControl
    {
    }
    // Specifies a type that indicates the assembly to search, and the name 
    // of an image resource to look for.
    [ToolboxBitmap(typeof(MyControl), "MyControlBitmap")]
    class MyControl : UserControl
    {
    }
    

    // Specifies the bitmap associated with the Button type.
    /** @attribute ToolboxBitmap(Button.class)  */
    class MyControl1 extends UserControl
    {
    }
    // Specifies a bitmap file.
    /** @attribute ToolboxBitmap("C:\\Documents and Settings\\Joe\\MyPics\\myImage.bmp")*/
    class MyControl2 extends UserControl
    {
    }
    // Specifies a type that indicates the assembly to search, and the name 
    // of an image resource to look for.
    /* @attribute ToolboxBitmap(MyControl.class, "MyControlBitmap") */
    class MyControl extends UserControl
    {
    }
    

See Also

Community Additions

ADD
Show:
© 2014 Microsoft