Nevron Forum

Use a Factory Shape as part of an NCompositeShape

https://www.nevron.com/Forum/Topic7645.aspx

By Mohamed Salti 1 - Thursday, April 4, 2013

Hello,

I would like to use shapes provided by your shape factory as a part of my NCompositeShape.

According to the documentation I should be able to use the Compose() method provided by the NShape object to do this.

The following code throws the exception: 'The specified node cannot be inserted at index: 0'

//CODE START

NFlowChartingShapesFactory f = new NFlowChartingShapesFactory(NGraphicsUnit.Pixel, 96);
f.DefaultSize = new NSizeF(80, 60);

var zz = f.CreateShape(FlowChartingShapes.Document);
zz.Compose(this); //exception thrown on this line. FYI 'this' inherits from NCompositeShape

//CODE END

Any help with this would be greatly appreciated.

Thanks!
By Nevron Support - Thursday, April 4, 2013

Hi,

We have just tested a piece code that mimics your scenario and it works fine. Here it is, try it out:

CustomCompositeShape compositeShape = new CustomCompositeShape();

document.ActiveLayer.AddChild(compositeShape);

compositeShape.Initialize();

compositeShape.Location = new NPointF(100, 100);

 

...

 

[Serializable]

public class CustomCompositeShape : NCompositeShape

{

        public void Initialize()

        {

               NBasicShapesFactory factory = new NBasicShapesFactory();

               factory.DefaultSize = new NSizeF(100, 100);

 

               NShape shape1 = factory.CreateShape(BasicShapes.Rectangle);

               shape1.Compose(this);

 

               NShape shape2 = factory.CreateShape(BasicShapes.Circle);

               shape2.Location = new NPointF(100, -50);

               shape2.Compose(this);

 

               UpdateModelBounds();

        }

}

By Mohamed Salti 1 - Friday, April 5, 2013

Thanks! I had some dll version issues on my local machine, once fixed my original code worked.

Thanks again!