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
[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
{
namespace Microsoft.VisualBasic.PowerPacks.Design
{
[Serializable]
internal sealed class LineShapeToolboxItem : ShapeToolboxItem
{
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)
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