I have developed a control in C#. Among other things this control can popup other controls at runtime. When you include the assembly in Visual Studio, the control that I created shows up, but the other controls (the ones my control uses) show up as well. I would rather not have them show up in the toolbox in Visual Studio. Is there an Attribute that I can apply to these classes to make them not show up? I found the browsable attribute, but it says it is for properties and events.
A:
If you declare a UserControl as "internal" instead of "public", it will not show up in the toolbox when you reference the Assembly in another project.
Update: or maybe that doesn't work at all. I can't get my simple test controls to work right when I try to host one in another. Let me know if "internal" works.
MusiGenesis
2009-09-15 01:44:26
I have verified that making it internal did not help.
Pat O
2009-09-15 21:09:25
That's weird - making it internal *did* keep it out of the toolbox of my consuming project. Oh well, obviously the ToolboxItem attribute makes a lot more sense.
MusiGenesis
2009-09-15 21:54:58
+6
A:
Add the [ToolboxItem(false)] attribute to the classes that you don't want to show up in the toolbox.
Josh Einstein
2009-09-15 02:03:40
That worked now I need to figure out how to set an Icon. I tried ToolboxBitmap, but have not succeeded in getting it to work yet.
Pat O
2009-09-15 21:10:31
ToolboxBitmap is the correct attribute. You need to add a .bmp file to your project and make sure its build action is set to Resource. Then, assuming it's called Example.bmp and in the same folder as your control, your ToolboxBitmap attribute would look something like:namespace MyControls { [ToolboxBitmap(typeof(MyControl), "Example.bmp")] public sealed class MyControl : Control { }}
Josh Einstein
2009-09-16 01:55:39