It is not easy to understand what the MSDN documentation for this topic actually means.
Firstly I think the attribute is easier to understand if full names are used for the Type,
e.g.
namespace ControlLib {
[ToolboxBitmap(typeof(ControlLib.MyUserControl), "Bitmaps.red.bmp")]
public partial class MyUserControl : UserControl {
public MyUserControl() {
InitializeComponent();
}
}
}
The name of the resource implied by that attribute is
resourcename = "ControlLib" + "." + "Bitmaps.red.bmp"
So how do we create the
ControlLib.Bitmaps.red.bmp
resource?
Assuming a project with the default namespace ControlLib
1) Add the file red.bmp to the Bitmaps subdirectory<br />
2) In Solution Explorer right click the file to get the properties page and change the Build Action from None to Embedded Resource
Note that a resource added in this way is not accessible via the designer generated strongly typed resource class ControlLib.Properties.Resources.
Any project referencing the ControlLib assembly should see custom toolbox bitmaps. In my rather old VS (c# express 2005) there are some difficulties
1) The default bitmaps are used when the assembly is added as a project reference.<br />
2) Custom bitmaps are not automatically refreshed and if changed must be deleted from the toolbox and readded via the Choose Toolbox Items dialog.
Finally I struggled to figure out when
[ToolboxBitmap(Type)]
would be used, but this note from 2006 (
http://support.microsoft.com/kb/311315[
^]) makes it clear that it allows you to use the custom bitmap from an existing control. For example if your custom control is a modified ProgressBar you may want to use that bitmap. Here's how:
namespace ControlLib {
[ToolboxBitmap(typeof(System.Windows.Forms.ProgressBar))]
public class MyProgressBar : ProgressBar {
Alan.