Create shapes with complex geometry in Nevron Diagram

Applies to: Nevron Diagram for .NET

How to create shapes with complex geometry in Nevron Diagram?



In Nevron Diagram for .NET you can create custom shapes with complex geometry.
The following code example demonstrates how to create a rectangle with two wholes (a complex polygon):

[C#]

// Create a graphics path that represents the model of the polygon
GraphicsPath path = new GraphicsPath();
path.AddRectangle(new RectangleF(0, 0, 200, 200));
path.AddRectangle(new RectangleF(20, 20, 70, 160));
path.AddRectangle(new RectangleF(110, 20, 70, 160));
 
// Host the graphics path in a NCustomPath primitive
NCustomPath pathPrimitive = new NCustomPath(path, PathType.ClosedFigure);
 
// Create a composite shape and put the path primitive in it
NCompositeShape shape = new NCompositeShape();
shape.Primitives.AddChild(pathPrimitive);
 
// Add the composite shape to the drawing document's active layer
nDrawingDocument1.ActiveLayer.AddChild(shape);
 
// Update the model bounds
shape.UpdateModelBounds();
 
// Reposition the shape
shape.Location = new NPointF(50, 50);

[VB.NET]
' Create a graphics path that represents the model of the polygon
Dim path As New GraphicsPath()
path.AddRectangle(New RectangleF(0, 0, 200, 200))
path.AddRectangle(New RectangleF(20, 20, 70, 160))
path.AddRectangle(New RectangleF(110, 20, 70, 160))
 
' Host the graphics path in a NCustomPath primitive
Dim pathPrimitive As New NCustomPath(path, PathType.ClosedFigure)
 
' Create a composite shape and put the path primitive in it
Dim shape As New NCompositeShape()
shape.Primitives.AddChild(pathPrimitive)
 
' Add the composite shape to the drawing document's active layer
NDrawingDocument1.ActiveLayer.AddChild(shape)
 
' Update the model bounds
shape.UpdateModelBounds()
 
' Reposition the shape
shape.Location = New NPointF(50, 50)


Article ID: 207, Created On: 2/24/2012, Modified: 2/24/2012