Monday, 28 February 2005

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

public class MyUserControl : System.Windows.Forms.UserControl {...}

2) create a class, derived from ToolboxItem class

using System.Runtime.Serialization;

public class MyToolboxItem : ToolboxItem{
   public MyToolboxItem() : base(){

MyToolboxItem (Type type) : base(type){

       //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
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*

coden | dddwik | faq
Monday, 28 February 2005 23:27:58 (GMT Standard Time, UTC+00:00)  #    Comments [78]  | 
Tuesday, 22 February 2005

How to install a .NET usercontrol library in Visual Studio, so that it appears in the reference list and in the customize toolbox list without explicit add the dll manually?


Just add the path of the dll into the following registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders

coden | faq
Tuesday, 22 February 2005 23:19:45 (GMT Standard Time, UTC+00:00)  #    Comments [38]  | 

Theme design by Jelle Druyts

Pick a theme: