Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying custom icon for custom control?

In visual studio when you create a custom control you get this default toolbox icon ugly little purple gear thing for an icon of your control instead of a custom control default toolbox icon.

So how can I change the icon for my control?

like image 830
Kredns Avatar asked Apr 13 '09 01:04

Kredns


People also ask

How do I add a custom icon?

Go to the folder or file you want a new icon for, go to Properties, go to Customize (or if it is already on the first selection then it should say "Change icon") and change the icon. Save the *. ico version of the file on your desktop. It makes for easier finding later.

What is a custom icon?

A custom icon is for icons which have a very specific or unique action.


1 Answers

  1. Put your icon (for exemple "icon.bmp" 16x16 pixels) on the root folder of your custom control project
  2. Include this line just before your control class : [ToolboxBitmap(typeof(yourControl), "yourControl.bmp")]

Here are further steps you need to take care of:-

  1. Verify your bitmap has the following properties : Height of 16 pixel Width of 16 pixel Bitmap saved as 16 colors bmp file
  2. Give it the same name as the class of your custom control (ie : yourControl.bmp)
  3. Place it in the same directory, and then make it an embedded resource of your assembly.
  4. To enable the bitmap as an embedded resource, right-click the bitmap file and select the Properties menu item. From the Properties page, set the Build Action to Embedded Resource.
  5. So when you will place your control in a page, the Toolbox will search the assembly manifest for an embedded bitmap with the same qualified name as the control, here is the reason why the bitmap must have the same name as the class of your control.

For further discussion on this you can refer to this

like image 101
hellowahab Avatar answered Oct 22 '22 12:10

hellowahab