Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Custom Contro Icon
 

Custom Contro 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?
MigrationUser 1  Thursday, February 06, 2003 4:05 PM
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
MigrationUser 1  Thursday, February 06, 2003 4:08 PM

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.
 :^)
MigrationUser 1  Thursday, February 06, 2003 9:57 PM
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?
MigrationUser 1  Thursday, February 06, 2003 10:04 PM
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.
MigrationUser 1  Thursday, February 20, 2003 9:51 AM
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. 
MigrationUser 1  Thursday, February 20, 2003 10:10 AM
I did not know you could use other sizes/color depths. Thanks for the info.
MigrationUser 1  Thursday, February 20, 2003 2:06 PM
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?
MigrationUser 1  Thursday, February 20, 2003 2:12 PM
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. 
MigrationUser 1  Friday, February 21, 2003 9:29 AM
crazy, i wonder why they picked that one?  :~ 
MigrationUser 1  Friday, February 21, 2003 3:10 PM

You can use google to search for other answers

Custom Search

More Threads

• Serialization logic for a custom XML serializer
• How can I use the Forms Designer colour ComboBox control?
• Running an application offline and send updates to the database later
• designer errors: Object reference not set to an instance of an object
• Design view slow to load
• System.ComponentModel
• Toolbar Button Problems...
• Accessing GroupName information from GetPropertyValues and SetPropertyValues in the custom SettingsProvider
• Multiline Attribute used in TextBox.Text property
• designer view causes vc# to crash - please help