Ioannis Panagopoulos blog

Tutorials on HTML5, Javascript, WinRT and .NET

Displaying a custom Icon on the Toolbox for a Custom Control

by Ioannis Panagopoulos

Let's say you have created a nice Custom Control named "LimitedListTextBox". This control should now appear on the Toolbox with a "gear" icon. If you want to supply your own icon you must do the following:

Create or add a new item to the project. The item should be a Bitmap Image with the same name as the control (in our case LimitedListTextBox.bmp) and should be located (for the easiest case) at the same folder the code fort the control resides.The bitmap should be 16x16 with 16 colors (4bit) and should be defined as an "Embedded Resource" for the project. Below is an example for the LimitedListTextBox Control:



Now go ahead and add the following code just above the definition of the Custom Control's class:

[ToolboxItem(true)]
[ToolboxBitmapAttribute(typeof(LimitedListTextBox),"LimitedListTextBox.bmp"]
public partial class: UserControl
{
     /// Your code here
}


The default icon now will be changed. Note that the control's icon does not show on solutions that contain the project for the control. You only see the icon after you have created the Release/Debug binary version of the control library and imported it from another project as a .dll assembly.
blog comments powered by Disqus
hire me