Custom Control Icon
Hi!!
I have make an custom Control that inherits from textbox and adds it severar validation functions and maskedit. Now I want to add a icon to this control to showit in the IDE ToolBox and add it to forms in design graphical mode.
How can I add a "toolbox Icon" to my control?
just right mouse click on the toolbar where you want to have it show up at, right mouse click, then click on Customize Toolbox. On the .NET Components tab, click the browse button and find the Assembly your custom control is in, hit ok and it should be there :)
<edit>
ack, sorry, i misread your post...here's how to add an icon...this assumes VS.NET...
add an image to your project, click on the image and go to it's properties...change the Build Action to Embedded Resource
then, add this attribute to your control (at the top of the class)
ToolboxBitmap(GetType(MyCustomControl), "MyIcon.bmp")
</edit>
16 x 16 is the requirement for an icon...I believe you can so many different file formats...i use either ico or bmp
Thank you,
I do something like this:
<ToolboxBitmap(GetType(ValidText), "ValidText.bmp")> _
Public Class ValidText
and I add the ValidText.bmp to the project, but ToolboxBitmap not is recogniced only Toolboxitem and Toolboxitemfilter.
What can it be?
Give an email and i send you my custom control an help me.
:^)
make sure your bmp is 16x16 and I think it needs to be 256 colors or less (i might be wrong about that though)...i've had problems in the past with some bitmaps too, did you try an ico file?
FWIW, you needn't specify the name of the bitmap if it's the same as the class name and you've set the BuildAction property for the bitmap to Embedded Resource. That is, the ToolboxBitmapAttribute constructor allows you to specify just the type (and it will find the matching bitmap). Also, I've had good luck simply including the resource in the assembly and not adding the ToolBoxBitmap attribute at all--that is, if the icon has the same root name as the class, then .NET finds it and uses it. I've used both 16x16 and 32x32 bitmaps for toolbox bitmaps, but you are limited to 256 colors. In addition, the toolbox uses the pixel in the lower-left corner of the bitmap as the transparent background color, so take that into consideration when choosing a bitmap.
If you're not seeing your bitmap, my guess is that either you're using a bitmap that's too large, has too many colors, or you've neglected to set the BuildAction property for the bitmap resource to Embedded Resource.
If you put a bitmap with the same name as your class in the same project and namespace as your class, VS will find it. It must be 16x16 and 16 color, and set to "Embedded Resource". A common mistake is to forget to set the default namespace in the project properties. If you don't set that correctly, the bitmap will be stored in the wrong namespace and will never be found. If you open your assembly with Reflector, you can see if this is the problem.
It is not necessary to use an attribute.
I did not know you could use other sizes/color depths. Thanks for the info.
thanx for posting all those details guys, appreciate it :)
Ken Getz, I thought it was the upper-left hand corner (0, 0) that the transparency comes from. Is that not the case?
I had read somewhere it was the lower-left, and had tried it with ASP.NET custom controls. Just checked it with WinForms custom controls, and it's definitely the lower-left pixel that controls the transparent color. At least, it sure appears that way in my simple tests.
crazy, i wonder why they picked that one? :~