Work with layers in Nevron Diagram for .NET

Applies to: Nevron Diagram for .NET

How to work with layers in Nevron Diagram for .NET?

The content of each drawing is divided in layers. The layers of a drawing are contained in a NLayerCollection instance, accessible from the Layers property. Of all layers in a drawing only one can be active at a time. The active layer is obtained from the ActiveLayer property and is specified by the ActiveLayerUniqueId property. By default each drawing is created with only one layer, which is at the same time the active layer.



The following code adds two layers to a drawing document and makes the first layer the currently active one:

[C#]
using Nevron.Diagram;
using Nevron.Diagram.Shapes;
using Nevron.Diagram.Templates;
using Nevron.GraphicsCore;
...
// create the tree layer and modify its styles
NLayer treeLayer = new NLayer();
treeLayer.Name = "Tree Layer";
  
treeLayer.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(30, 30, 0));
treeLayer.Style.FillStyle = new NColorFillStyle(Color.FromArgb(0xaa, 0xaa, 0));
treeLayer.Style.ShadowStyle = new NShadowStyle(
    ShadowType.Solid,
    Color.FromArgb(50, 0, 0, 0),
    new NPointL(3, 3),
    1,
    new NLength(1));
  
// add it to the document and make it the active one
nDrawingDocument1.Layers.AddChild(treeLayer);
nDrawingDocument1.ActiveLayerUniqueId = treeLayer.UniqueId;
  
// create a tree template with pentagons in it
NGenericTreeTemplate treeTemplate = new NGenericTreeTemplate();
treeTemplate.VerticesShape = BasicShapes.Pentagon;
treeTemplate.Origin = new NPointF(10, 10);
  
// create it
treeTemplate.Create(nDrawingDocument1);
  
// create the shapes layer and modify its styles
NLayer shapesLayer = new NLayer();
shapesLayer.Name = "Shapes Layer";
  
shapesLayer.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(0x00, 0x00, 0xaa));
shapesLayer.Style.FillStyle = new NColorFillStyle(Color.FromArgb(0xaa, 0xaa, 0xff));
shapesLayer.Style.ShadowStyle = new NShadowStyle(
    ShadowType.Solid,
    Color.FromArgb(80, 0, 0, 0),
    new NPointL(3, 3), 1,
    new NLength(1));
  
// add it to the document and make it the active one
nDrawingDocument1.Layers.AddChild(shapesLayer);
nDrawingDocument1.ActiveLayerUniqueId = shapesLayer.UniqueId;
  
// create two shapes in it
NRectangleShape rect = new NRectangleShape(new NRectangleF(60, 60, 70, 70));
shapesLayer.AddChild(rect);
  
NEllipseShape ellipse = new NEllipseShape(new NRectangleF(120, 120, 70, 70));
shapesLayer.AddChild(ellipse);
  
// make the tree layer the currently active one
nDrawingDocument1.ActiveLayerUniqueId = ((NLayer)nDrawingDocument1.Layers.GetChildAt(1)).UniqueId;

[VB.NET]
Imports Nevron.Diagram
Imports Nevron.Diagram.Shapes
Imports Nevron.Diagram.Templates
Imports Nevron.GraphicsCore
...
' create the tree layer and modify its styles
Dim treeLayer As New NLayer()
treeLayer.Name = "Tree Layer"
  
treeLayer.Style.StrokeStyle = New NStrokeStyle(1, Color.FromArgb(30, 30, 0))
treeLayer.Style.FillStyle = New NColorFillStyle(Color.FromArgb(&Haa, &Haa, 0))
treeLayer.Style.ShadowStyle = New NShadowStyle(ShadowType.Solid, Color.FromArgb(50, 0, 0, 0), New NPointL(3, 3), 1, New NLength(1))
  
' add it to the document and make it the active one
nDrawingDocument1.Layers.AddChild(treeLayer)
nDrawingDocument1.ActiveLayerUniqueId = treeLayer.UniqueId
  
' create a tree template with pentagons in it
Dim treeTemplate As New NGenericTreeTemplate()
treeTemplate.VerticesShape = BasicShapes.Pentagon
treeTemplate.Origin = New NPointF(10, 10)
  
' create it
treeTemplate.Create(nDrawingDocument1)
  
' create the shapes layer and modify its styles
Dim shapesLayer As New NLayer()
shapesLayer.Name = "Shapes Layer"
  
shapesLayer.Style.StrokeStyle = New NStrokeStyle(1, Color.FromArgb(&H0, &H0, &Haa))
shapesLayer.Style.FillStyle = New NColorFillStyle(Color.FromArgb(&Haa, &Haa, &Hff))
shapesLayer.Style.ShadowStyle = New NShadowStyle(ShadowType.Solid, Color.FromArgb(80, 0, 0, 0), New NPointL(3, 3), 1, New NLength(1))
  
' add it to the document and make it the active one
nDrawingDocument1.Layers.AddChild(shapesLayer)
nDrawingDocument1.ActiveLayerUniqueId = shapesLayer.UniqueId
  
' create two shapes in it
Dim rect As New NRectangleShape(New NRectangleF(60, 60, 70, 70))
shapesLayer.AddChild(rect)
  
Dim ellipse As New NEllipseShape(New NRectangleF(120, 120, 70, 70))
shapesLayer.AddChild(ellipse)
  
' make the tree layer the currently active one
nDrawingDocument1.ActiveLayerUniqueId = DirectCast(nDrawingDocument1.Layers.GetChildAt(1), NLayer).UniqueId

Article ID: 116, Created On: 11/8/2010, Modified: 12/1/2010