You can do this in different ways explained below. In all the cases the bitmap or icon should follow these rules: - The bitmap or icon dimension should be 16X16 with 16 colors.
- The left-bottom pixel-color will be assumed to be the transparent color.
Technique 1:
Use a bitmap (not an icon, in the embedded resource) file implicitly without specifying the ToolboxBitmapAttribute for the type:
Say, you have a custom control MyControl in the namespace MyNamespace, create a bmp file MyControl.bmp following the above rules.
Add this file to your project at the top-level and make it an embedded resource. The project's default namespace should be MyNamespace.
If the control's namespace and the project's default namespace don't match then move the bitmap to appropriate subfolders so that they match. If this is not possible, typically when the namespaces are not related at all then you cannot use this technique, use instead one of the techniques below using the ToolboxBitmap attribute.
Create the assembly and the next time you add it to the toolbox the custom image in MyControl.bmp should be available in the toolbox.
This is the easiest technique to implement as it doesn't require you to use the ToolboxBitmapAttribute in your type defenition.
Technique 2:
Use ToolboxBitmap attribute.
Example 1:
Use a bitmap (not icon) in the embedded resource with the same name as the type.
Default Assembly Namespace: "MyAssemblyNamespace"
|