Wednesday, July 21, 2004

Adding icon to usercontrols [to display in toolbox]

I did find a way doing it manually, but I don't know if it's the correctway to do it ... but it works !1) Create your usercontrol / Component (e.g MyUserControl class) andmarkup the class with[ToolboxBitmap(typeof(Bitmap))] attribute2) Compile this class into a module (Yeha a module, could not get theassembly to work!!)csc /t:module MyUserControl.csThis will create a file called MyUserControl.netmodule3) Create a bitmap 16x16x16, with the fully qualified name of the classthat has the attribute. i.e. namespace.classname.bmpIn my case since the class does not live in a namespace I useMyUserControl.bmp4) Use the al.exe (Assembly Linker) tool to embed the resource.
Al MyUserControl.netmodule
/t:library /embed:MyUserControl.bmp/out:MyUserControl.dll
This step will create an assembly linking the MyUserControl.netmoduleand the embed resource file!5) Add this control to your toolbox !