Use the ToolboxBitmapAttribute for custom bitmaps
There are times when you may need to create custom Web or Windows controls in
Visual Studio .NET. Along with these controls, you may wish to provide bitmaps
that describe their use. This is where System.Drawing.ToolboxBitmapAttribute
comes into play. This attribute is used to associate a
bitmap with a control by providing either a filename or class type, from
which the bitmap will be extracted. When you design the bitmap, make sure it is
16 X 16 pixels. The perimeter of the bitmap is used as a mask, so make sure it
is the same color all the way around.

Specifying a resource name
After designing your bitmap, make sure it is included either in the project that
contains the control that it is associated with or in a
referenced assembly. Also make sure the you set its Build Action to Embedded
Resource.
[ToolboxBitmapAttribute(typeof(Wizard), "ToolboxBitmaps.Wizard.bmp")]
The first parameter identifies the assembly from which the bitmap will be
loaded. This is done by providing a type. The type may either be defined in the
current assembly, or in a referenced assembly. Any type in the assembly may be
used, as long as its namespace corresponds to the namespace of the resource.
The second parameter identifies the resource name of the bitmap.
This resource name, together with the namespace of the
type, must represent the fully qualified name (full namespace and
name) of the resource. A resource namespace is equal to the Default Namespace,
as defined in Project Properties, plus any subfolders in the project. Using the
example, "ToolboxBitmaps.Wizard.bmp" indicates to look for the Wizard.bmp file
in the ToolboxBitmaps sub-namespace. Sub-namespaces for resources are created
simply by creating subfolders in your project. In other words, the
"ToolboxBitmaps" sub-namespace is really a subfolder in the project.
Tip: A quick way to determine the namespace for your
resource is to use ILDASM.
Specifying a class type
[ToolboxBitmapAttribute(typeof(Wizard))]
By specifying only a class type, the bitmap must be a part of the same namespace
as the class. A resource namespace is equal to the Default Namespace, as
defined in Project Properties, plus any subfolders in the project.
Back to Tips and Tricks