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 classusing 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*
Remember Me
a@href@title, strike
Theme design by Jelle Druyts
Pick a theme: BlogXP business calmBlue Candid Blue dasBlog dasblogger dasblueblog dasEmerald DirectionalRedux Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream Portal Project84 Project84Grass Slate Sound Waves Tricoleur useit.com Voidclass2
Powered by: newtelligence dasBlog 2.3.9074.18820
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2010, Your Name Here
E-mail