problems with NStep2Conector


https://www.nevron.com/Forum/Topic8836.aspx
Print Topic | Close Window

By Hans Henrik Friis Pedersen - 10 Years Ago
Hi,

When using the code below; no HV connector line is shown between the rectange and the table - Why?

Both th table and the rectange is shown but not the connector line??

================

NTableShape table = new NTableShape(10, 10, 100, 100);
table.InitTable(2, 2);
table[0, 0].Text = "Cell 1";
table[1, 0].Text = "Cell 2";
table[0, 1].Text = "Cell 3";
table[1, 1].Text = "Cell 4";
document1.ActiveLayer.AddChild(table);

NRectangleShape rect1 = new NRectangleShape(new NRectangleF(150, 150, 50, 50));
document1.ActiveLayer.AddChild(rect1);

NStep2Connector hv1 = new NStep2Connector(false);
hv1.StyleSheetName = NDR.NameConnectorsStyleSheet;
hv1.Text = "HV1";
hv1.FromShape = table;
hv1.ToShape = rect1;
document1.ActiveLayer.AddChild(hv1);


By Nevron Support - 10 Years Ago
Hi, there are 2 problems with your code:
  1. When you set the From and To shapes of the connector it is not added to the document yet, and that is why the From and To shapes cannot be properly resolved and the connector does not appear in the document. You should always add a connector to the document first and then set its From and To shapes.
  2. You create a rectangle shape by using the rectangle shape class, but shapes by default does not have ports and you cannot attach a connector to a shape that does not have ports. You can easily resolve this by using the shape factories of Nevron Diagram for .NET to create shapes. Shape factories automatically add a default set of ports to the shapes they create.
The following is a modified version of your code that takes into account the aforementioned facts:


NBasicShapesFactory factory = new NBasicShapesFactory();

NTableShape table = new NTableShape(10, 10, 100, 100);
table.InitTable(2, 2);
table[0, 0].Text = "Cell 1";
table[1, 0].Text = "Cell 2";
table[0, 1].Text = "Cell 3";
table[1, 1].Text = "Cell 4";
document.ActiveLayer.AddChild(table);

NShape rect1 = factory.CreateShape(BasicShapes.Rectangle);
rect1.Bounds = new NRectangleF(150, 150, 50, 50);
rect1.CreateShapeElements(ShapeElementsMask.Ports);

document.ActiveLayer.AddChild(rect1);

NStep2Connector hv1 = new NStep2Connector(false);
document.ActiveLayer.AddChild(hv1);
hv1.Text = "HV1";
hv1.StyleSheetName = NDR.NameConnectorsStyleSheet;
hv1.FromShape = table;
hv1.ToShape = rect1;