Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having my userControl have its own icon on the toolbox

I made a control that inherits directly from ErrorProvider. I thought that applying it the ToolboxBitmap attribute would be enough to get my control to have the same icon on the toolbox as the original control has, but it doesn't. It's strange, as if I add the control to the form, it will appear just as it should, but it doesn't change the toolbox's icon. What am I missing here? I already restarted visual studio and it keeps this behavior.

[ToolboxBitmap(typeof(ErrorProvider))]
public class ErrorProviderEx : ErrorProvider {
...
}
like image 614
devoured elysium Avatar asked Jul 22 '09 06:07

devoured elysium


3 Answers

In Visual Studio 2008, the icon specified by ToolBoxBitmap is not added to the toolbox for any of the components in the current solution for performance reasons. The standard 'gear' icon is used. If you manually add your assembly through the Toolbox...Add Items...dialog, the custom icon will display which is the behavior you are experiencing. Moreover, when you drag ErrorProviderEx to a form, the icon you specified will be used, which again is the behavior you noted in a comment.

Note, in your case, you are using typeof(ErrorProvider) so you will not have the normal problems of using a custom bitmap.

(This behavior may also been true for Visual Studio 2005. Visual Studio 2003 spoiled us by displaying the icon.) (I personally do not like this new behavior. I am willing to wait an extra second or two for the IDE to retrieve the icon for all controls and components in the solution. I wonder if there is a registry hack to show the icons.)

like image 106
AMissico Avatar answered Sep 21 '22 13:09

AMissico


Is it in the same project? Or a dll you are referencing?

You only get proper icons when referncing a fixed dll. Try building a control dll and referencing it.

like image 25
Marc Gravell Avatar answered Sep 18 '22 13:09

Marc Gravell


So there is a work-around. Supposing your UserControl is in "MyControl" project, add a referrence to itself. That is: Referrence MyControl project in the MyControl project, like you would do in another project. Then the icon will be displayed in the Toolbox of that MyControl project, too.

like image 27
K128Sura Avatar answered Sep 20 '22 13:09

K128Sura