Why doesn't ToolboxBitmapAttribute work?
Asked Answered
F

1

7

I have a UserControl in my project called 'UIWizard.cs', and a 24-bit Bitmap named 'UIWizardToolboxBitmap.bmp' that has it's build action set to 'Embedded Resource'. I verified that it does exist in the manifest:

.mresource public BitFlex.Windows.Forms.Resources.UIWizardToolboxBitmap.bmp
{
    // Offset: 0x00000000 Length: 0x00000336
}

I have tried these attribute declarations:

[ToolboxBitmap(typeof(UIWizard), "BitFlex.Windows.Forms.Resources.UIWizardToolboxBitmap.bmp")]
public partial class UIWizard : UserControl {

[ToolboxBitmap(typeof(UIWizard), "UIWizardToolboxBitmap.bmp")]
public partial class UIWizard : UserControl {

[ToolboxBitmap(typeof(UIWizard), "UIWizardToolboxBitmap")]
public partial class UIWizard : UserControl {

When I set my library to 'Release Build' and reference it in another project and add the ToolBox items manually using Choose Items... it still fails to display my bitmap properly. I want to avoid using a absolute path, because this is a source controlled project, and not everyone will be using the same mappings.

MSDN really isn't much help as the documentation on the ToolBoxBitmapAttribute is lacking, and most of what's on the web is pretty vague.

Femininity answered 13/8, 2010 at 22:7 Comment(1)
Possible duplicate of Displaying custom icon for custom control?Dermatologist
M
2

It is all bitmap format.
1. If I remember right we are used 256 colors, 16x16 73DPI bitmap.
2. Also try to add [ToolBoxItem(true)] to your class

Monoceros answered 15/8, 2010 at 19:30 Comment(3)
[ToolboxBitmap(typeof(UIWizard), "Resources.UIWizardToolboxBitmap")] [ToolBoxItem(true)] public partial class UIWizard : UserControl { Works.Femininity
I can not get any of this to save my life! I have done everything suggested and still get that dumb purple gear in the toolbox! Also, I thought is was supposed to be a 16 color, 16x16 pixel?Dermatologist
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.Dermatologist

© 2022 - 2024 — McMap. All rights reserved.