After many hours of search for a possibility to change the name and bitmap of my custom user controls in the Visual Studio Toolbox, here is the solution.
1) Set the ToolboxItem Attribute to the UserControl
[ToolboxItem(typeof(MyToolboxItem))]
public class MyUserControl : System.Windows.Forms.UserControl {...}
2) create a class, derived from ToolboxItem class
using System.Runtime.Serialization;
using System.Drawing.Design;
[Serializable]
public class MyToolboxItem : ToolboxItem{
public MyToolboxItem() : base(){
DoMagic();
}
public MyToolboxItem (Type type) : base(type){
DoMagic();
}
void DoMagic(){
//set the desired text
base.DisplayName = "MyText";
//load the embedded resource bitmap
base.Bitmap = new System.Drawing.Bitmap(GetType().Module.Assembly.GetManifestResourceStream("MyBitmap.bmp"));
}
//a very special constructor
private MyToolboxItem (SerializationInfo info, StreamingContext context) {
base.Deserialize(info, context);
}
}
some notes:
At First, if you try to "override" the DisplayName and Bitmap properties, it won't work. It will only work, if these base properties are set in the constructor ... very strange.
Second, the private deserialize constructor must be set, else the ToolboxItem will throw an exception if you try to insert it in the form ... many thanks to reflector for solving this problem *g*