Displaying custom icon for custom control?
Asked Answered
F

2

12

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?

Freeload answered 13/4, 2009 at 1:22 Comment(0)
A
9

Use the ToolboxBitmap attribute on the class.

Austreng answered 13/4, 2009 at 1:24 Comment(0)
D
16
  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

Dryly answered 29/5, 2014 at 13:12 Comment(3)
This one is by far the best answer, very detailed! Just got it to work. For everyone else that can't get it to work for some reason, make sure you are using the correct namespace! On my new UserControl I imported it from somewhere else and it had a different namespace. I had to change it to the new project's namespace (right click on the project, go to properties, and under the application tab check the "Default namespace". That should match the namespace defined in the code of the new UserControl.Waldrup
I used this explanation in VS2013 Prof and inside the form I get the nice custom icon. However in the toolbox, the ugly default usercontrol icon is still there.Deedeeann
Quote from this site : 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., which is indeed true.Deedeeann
A
9

Use the ToolboxBitmap attribute on the class.

Austreng answered 13/4, 2009 at 1:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.