ToolboxBitmap Problem

Jay1b

Member
Joined
Dec 12, 2007
Messages
21
Programming Experience
5-10
Hi

I'm trying to assign a toolbox icon for my custom control. The images are set as embedded resources and are stored in a folder called Images.

I have tried the following:

VB.NET:
<ToolboxBitmap(GetType(DockSpacerControl), "CommonControls.16x16Test.bmp")> _
Public Class DockSpacerControl

End Class

VB.NET:
<ToolboxBitmap(GetType(DockSpacerControl), "CommonControls.16x16Test.png")> _
Public Class DockSpacerControl

End Class

VB.NET:
<ToolboxBitmap(GetType(DockSpacerControl), "CommonControls.16x16Test.ico")> _
Public Class DockSpacerControl

End Class

VB.NET:
<ToolboxBitmap(GetType(DockSpacerControl), "16x16Test.bmp")> _
Public Class DockSpacerControl

End Class

VB.NET:
<ToolboxBitmap("16x16Test.bmp")> _
Public Class DockSpacerControl

End Class

None of which have worked... Am i missing out something?

Thanks
 
I have the same problem. I tried many exapmles from various sources but not a single worked - still getting the old gear-like icon in toolbox :(
I am beginning to fear that this is an issue of Express version.
 
Well I have the professional edition (with MSDN Premium subscription) so I dont think its just a problem with the Express version.
 
There is only one way I have know this to work. Basically, first you have to rename your Bitmap resource to match the fully qualified name of the control (including the namespace if it is a different namespace to the default one). For example, lets take the code below.

VB.NET:
Namespace Controls

    <ToolboxBitmap(GetType(CButton))> _
    Public Partial Class CButton 
        Inherits System.Windows.Forms.Button
   
       'Some Code
    End Class

End Namespace

The way it would work is that the bitmap (CButton.bmp) would have to be renamed to "Controls.CButton.bmp". This is because the control is in the namespace "Controls". When you have renamed the image file, right click the same folder that your control is in, in the Solution Explorer and click "Add -> Existing Item..." Select "All Files" from the type drop down list and select your image file (Controls.CButton.bmp). Once you have added it to the same folder as your control, make sure under "Properties" it is marked as an Embedded Resource. Once you have done that it should all work fine.
 
Back
Top