Click here to Skip to main content
15,031,193 members
Please Sign up or sign in to vote.
2.67/5 (3 votes)
See more:
I created an OvalShape that inherited from Microsoft.VisualBasic.PowerPacks.OvalShape.
The control works great but it does no show up in the designer Toolbox.
How do I get the shape control to show up in the Toolbox?

I did some searching and tried playing with the attributes such as adding:
[ToolboxItem(true)]

Also thinking that maybe something I added caused the designer to not want to add it I created a test class where I inherited from the OvalShape and added nothing to it and it did not show up.
I have a few other controls I inherited from Button and Label and they show up fine.

Currently I'm using
Visual Studio Express 2012 Version 11.0.50727.42.VSLRSTAGE
Microsoft .NET Framework Version 4.5.50709
Windows 7

Thanks,
Vince

*/Edit\*
This may seem like a real beginner question but I have made controls before and never had problems getting them into the toolbox. Something real strange is happening when you inherit from Microsoft.VisualBasic.PowerPacks.OvalShape
Posted
Updated 17-Jun-14 4:30am
v2
Comments
ZurdoDev 16-Jun-14 13:33pm
   
Did you try right-clicking and adding it in?
DemSmiley 16-Jun-14 15:55pm
   
OK played around with that. If I force select it that way it pulls in the base class OvalShape not my AdvancedOvalShape. With my empty test class it does the same thing. However if I inherit from SimpleShape which OvalShape inherits from then my test class comes in correctly.
gggustafson 17-Jun-14 9:47am
   
Include the project containing your control in the solution. The project will be picked up automatically. I assume that your shape is in a UserControl or Control.

If you want properties to be displayed, I use something like

// ************************************ ControlBackgroundColor

[Category ( "Appearance" ),
Description ( "Gets/Sets control background color" ),
DefaultValue ( typeof ( SystemColors ), "Control" ),
Bindable ( true )]
public Color ControlBackgroundColor
{
:

Now when the control is brought onto the form, the property ControlBackgroundColor appears in the Properties view.
DemSmiley 17-Jun-14 10:09am
   
The project is included in the solution. And its not actually a control. the full object model hierarchy is
Myshape
Microsoft.VisualBasic.PowerPacks.OvalShape
Microsoft.VisualBasic.PowerPacks.SimpleShape
Microsoft.VisualBasic.PowerPacks.Shape
System.ComponentModel.Component
System.MarshalByRefObject
object
gggustafson 17-Jun-14 12:15pm
   
I believe that your problem is based on the failure to realize that the ToolBox contains controls. So objects like graphics object (rectangles, ellipses, etc.) cannot be included.
DemSmiley 17-Jun-14 13:33pm
   
Not true, although 90% of the things in the toolbox will be controls there are other things in there by default that aren't such as Timer. The original power pack shapes show up in there as well. I also have communication controllers that show up in the toolbox so I can drop them onto the form.
gggustafson 17-Jun-14 16:19pm
   
I was excluding things like Timers, DialogBoxes, and the like. So if there is a problem with the VB packs, can you just create your own control?

By the way, you indicated C# in your tags. Could there be a conflict between C# and VB in this case?
DemSmiley 18-Jun-14 9:00am
   
Thanks for your suggestions gggustafson

I have the same problem. I have not solved it so far, but to give some information:

SimpleShape derives from Shape, which is a Component (IComponent).

If you drag and drop for instance any of the predefined Shapes, such as LineShape, OvalShape, etc.. to your form they are added automatically to a ShapeContainer, which is created when not existing.
This ShapeContainer is a Control, managing the Shapes.

This behaviour is done by a custom ToolboxItem implementation. For instance for LineShape this ist done by LineShapeToolboxItem
C#
[ToolboxItem("Microsoft.VisualBasic.PowerPacks.Design.LineShapeToolboxItem, Microsoft.VisualBasic.PowerPacks.VsPackage, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
 [Designer("Microsoft.VisualBasic.PowerPacks.Design.LineShapeDesigner, Microsoft.VisualBasic.PowerPacks.VsPackage, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
 [ToolboxItemFilter("System.Windows.Forms")]
 [DesignTimeVisible(false)]
 [SResDescription("DescriptionLineShape")]
 [ToolboxBitmap(typeof (LineShape), "Microsoft.VisualBasic.PowerPacks.LineShape.bmp")]
 public class LineShape : Shape
 {


C#
namespace Microsoft.VisualBasic.PowerPacks.Design
{
  [Serializable]
  internal sealed class LineShapeToolboxItem : ShapeToolboxItem
  {



C#
namespace Microsoft.VisualBasic.PowerPacks.Design
{
  internal abstract class ShapeToolboxItem : ToolboxItem
  {


When writing a custom ToolBoxItem, the CreateComponentsCore method has to be overridden. This method is called, when the control/component, you select in the toolbox and drag &drop it on your form, should be created. It returns an array of Components. So you could for instance return 100 Labels, that then are inserted by the designer.

One very ugly thing is, that all these nice design stuff is hidden as internal (and often sealed) class within the Microsoft.VisualBasic.PowerPacks.Design namespace. the implemenattion is in

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualBasic.PowerPacks.VsPackage.dll

(you can have a look on it with some decompilers, such as DotNetPeek)


The SimpleShape does not have a specified ToolboxItem. You have to write your own one, which also means that you have to manage the stuff related to the ShapeContainer.

Beside the ToolboxItems, there are several Designer classes.

If you can manage the creation of your custom shape, which then is inserted into a ShapeContainer, and you have written your custom designer an exception will rise, after the ShapeConainter is added to Form.Controls and should be Painted, since
(within the ShapeContainerdesigner)
C#
 private void OnPaintShapeContainer(object sender, PaintEventArgs e)
    {
     ...
          Shape shape = (Shape) this.ShapeContainer.Shapes.get_Item(index);
          ShapeDesigner shapeDesigner = (ShapeDesigner) (object) designerHost.GetDesigner((IComponent) shape);
...  


your custom shape's designer is casted as ShapeDesigner, which is a class, you can not inherit from.....

It seems that Microsoft wants either you writing everything on your own, or to copy and paste disassembled code for modification....(which may not be allowed)
:o


Sincerely Yours
Martin
   
Comments
DemSmiley 18-Jun-14 8:48am
   
Thanks! That was what I was looking for, a reason as to why these classes were acting different.
The simplest and the best solution that worked for me is adding attribute
C#
DesignTimeVisible(true)
to inherited class.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900