Demonstrates page layers. Layers provide a powerful way to organize and manage the visibility and editing of different page items within a page. They allow you to segregate page items into different categories, which is particularly useful for handling complex diagrams.
Each shape can be assigned to multiple layers. In the example above, the Red shape is assigned to the Red layer, the Blue shape to the Blue layer, the Green shape to the Green layer, and the Grey shape is assigned to all layers (Red, Green, and Blue).
Use the Layers editor on the right side to explore the behavior of the different layer properties.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Diagram;
using Nevron.Nov.Diagram.Editors;
using Nevron.Nov.Diagram.Shapes;
using Nevron.Nov.Diagram.UI;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Text;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NLayersExample";
// Create the NOV example and its controls
NWidget exampleContent = CreateExampleContent();
NWidget exampleControls = CreateExampleControls();
if (exampleControls != null)
{
exampleControls.PreferredWidth = 300;
}
// Place the example and its controls in a pair box
NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
pairBox.FillMode = ENStackFillMode.First;
pairBox.FitMode = ENStackFitMode.First;
pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);
// Host the example in the form
NNovWidgetHost host = new NNovWidgetHost(pairBox);
host.Dock = DockStyle.Fill;
Controls.Add(host);
}
#endregion
#region Example
public NWidget CreateExampleContent()
{
// create a library browser that displays all predefined shape factories
NLibraryBrowser libraryBrowser = new NLibraryBrowser();
libraryBrowser.LibraryViewType = ENLibraryViewType.Thumbnails;
//NLibrary library = new NBasicShapeFactory().CreateLibrary();
//libraryBrowser.AddLibrarySection(library);
// create pan and zoom
NPanAndZoomView m_PanAndZoom = new NPanAndZoomView();
m_PanAndZoom.PreferredSize = new NSize(150, 150);
// create a drawing view
m_DrawingView = new NDrawingView();
m_DrawingView.HorizontalPlacement = ENHorizontalPlacement.Fit;
m_DrawingView.VerticalPlacement = ENVerticalPlacement.Fit;
// bind components to drawing view
libraryBrowser.DrawingView = m_DrawingView;
libraryBrowser.ResetLibrariesAsync();
m_PanAndZoom.DrawingView = m_DrawingView;
// create splitters
NSplitter libraryPanSplitter = new NSplitter();
libraryPanSplitter.Orientation = ENHVOrientation.Vertical;
libraryPanSplitter.SplitMode = ENSplitterSplitMode.OffsetFromFarSide;
libraryPanSplitter.Pane1.Content = libraryBrowser;
libraryPanSplitter.Pane2.Content = m_PanAndZoom;
NSplitter mainSplitter = new NSplitter();
mainSplitter.Orientation = ENHVOrientation.Horizontal;
mainSplitter.SplitMode = ENSplitterSplitMode.OffsetFromNearSide;
mainSplitter.SplitOffset = 370;
mainSplitter.Pane1.Content = libraryPanSplitter;
mainSplitter.Pane2.Content = m_DrawingView;
// Create the ribbon UI
NDiagramRibbonBuilder builder = new NDiagramRibbonBuilder();
m_DrawingView.Document.HistoryService.Pause();
try
{
InitDiagram(m_DrawingView.Document);
}
finally
{
m_DrawingView.Document.HistoryService.Resume();
}
return builder.CreateUI(mainSplitter, m_DrawingView);
}
public NWidget CreateExampleControls()
{
NStackPanel stackPanel = new NStackPanel();
NDesigner designer = NDesigner.GetDesigner(m_DrawingView.Content.Pages[0].Layers);
NNodeEditor editor = designer.CreateStandaloneEditor(m_DrawingView.Content.Pages[0].Layers);
stackPanel.Add(editor);
return stackPanel;
}
public string GetExampleDescription()
{
return @"
Demonstrates page layers. Layers provide a powerful way to organize and manage the visibility and editing of different page items within a page.
They allow you to segregate page items into different categories, which is particularly useful for handling complex diagrams.
Each shape can be assigned to multiple layers. In the example above, the Red shape is assigned to the Red layer, the Blue shape to the Blue layer, the Green shape to the Green layer,
and the Grey shape is assigned to all layers (Red, Green, and Blue).
Use the Layers editor on the right side to explore the behavior of the different layer properties.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Diagram Layers", "https://www.nevron.com/docs/openvision/diagram-layers.html"),
("Pages", "https://www.nevron.com/docs/openvision/diagram-pages.html"),
};
}
private void InitDiagram(NDrawingDocument drawingDocument)
{
NDrawing drawing = drawingDocument.Content;
// hide the grid
drawing.ScreenVisibility.ShowGrid = false;
// create several layers
NLayer redLayer = new NLayer();
redLayer.Color = NColor.Red;
redLayer.Name = "Red";
drawing.ActivePage.Layers.Add(redLayer);
NLayer greenLayer = new NLayer();
greenLayer.Color = NColor.Green;
greenLayer.Name = "Green";
drawing.ActivePage.Layers.Add(greenLayer);
NLayer blueLayer = new NLayer();
blueLayer.Name = "Blue";
blueLayer.Color = NColor.Blue;
drawing.ActivePage.Layers.Add(blueLayer);
// create several shapes, each assigned to different layer(s)
NBasicShapeFactory shapeFactory = new NBasicShapeFactory();
NShape redShape = shapeFactory.CreateShape(ENBasicShape.Rectangle);
redShape.Text = "Red";
redShape.Geometry.Fill = new NColorFill(NColor.Red);
redShape.SetBounds(10, 10, 100, 100);
redShape.AssignToLayers(redLayer);
drawing.ActivePage.Items.Add(redShape);
NShape greenShape = shapeFactory.CreateShape(ENBasicShape.Rectangle);
greenShape.Text = "Green";
greenShape.Geometry.Fill = new NColorFill(NColor.Green);
greenShape.SetBounds(120, 10, 100, 100);
greenShape.AssignToLayers(greenLayer);
drawing.ActivePage.Items.Add(greenShape);
NShape blueShape = shapeFactory.CreateShape(ENBasicShape.Rectangle);
blueShape.Text = "Blue";
blueShape.Geometry.Fill = new NColorFill(NColor.Blue);
blueShape.SetBounds(230, 10, 100, 100);
blueShape.AssignToLayers(blueLayer);
drawing.ActivePage.Items.Add(blueShape);
NShape grayShape = shapeFactory.CreateShape(ENBasicShape.Rectangle);
grayShape.Text = "Red, Green and Blue";
grayShape.Geometry.Fill = new NColorFill(NColor.Gray);
grayShape.SetBounds(10, 120, 320, 100);
grayShape.AssignToLayers(
redLayer,
greenLayer,
blueLayer);
drawing.ActivePage.Items.Add(grayShape);
}
#endregion
#region Implementation
#endregion
#region Event Handlers
#endregion
#region Fields
private NDrawingView m_DrawingView;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
} | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.Diagram
Imports Nevron.Nov.Diagram.Shapes
Imports Nevron.Nov.Diagram.UI
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Editors
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Forms
Public Class Form1
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Text = "NOV WinForms - NLayersExample"
' Create the NOV example and its controls
Dim exampleContent As NWidget = CreateExampleContent()
Dim exampleControls As NWidget = CreateExampleControls()
If Not exampleControls Is Nothing Then
exampleControls.PreferredWidth = 300
End If
' Place the example and its controls in a pair box
Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
pairBox.FillMode = ENStackFillMode.First
pairBox.FitMode = ENStackFitMode.First
pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)
' Host the example in the form
Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
host.Dock = DockStyle.Fill
Controls.Add(host)
End Sub
#End Region
#Region "Example"
Public Function CreateExampleContent() As NWidget
' create a library browser that displays all predefined shape factories
Dim libraryBrowser As NLibraryBrowser = New NLibraryBrowser()
libraryBrowser.LibraryViewType = ENLibraryViewType.Thumbnails
'NLibrary library = new NBasicShapeFactory().CreateLibrary();
'libraryBrowser.AddLibrarySection(library);
' create pan and zoom
Dim m_PanAndZoom As NPanAndZoomView = New NPanAndZoomView()
m_PanAndZoom.PreferredSize = New NSize(150, 150)
' create a drawing view
m_DrawingView = New NDrawingView()
m_DrawingView.HorizontalPlacement = ENHorizontalPlacement.Fit
m_DrawingView.VerticalPlacement = ENVerticalPlacement.Fit
' bind components to drawing view
libraryBrowser.DrawingView = m_DrawingView
libraryBrowser.ResetLibrariesAsync()
m_PanAndZoom.DrawingView = m_DrawingView
' create splitters
Dim libraryPanSplitter As NSplitter = New NSplitter()
libraryPanSplitter.Orientation = ENHVOrientation.Vertical
libraryPanSplitter.SplitMode = ENSplitterSplitMode.OffsetFromFarSide
libraryPanSplitter.Pane1.Content = libraryBrowser
libraryPanSplitter.Pane2.Content = m_PanAndZoom
Dim mainSplitter As NSplitter = New NSplitter()
mainSplitter.Orientation = ENHVOrientation.Horizontal
mainSplitter.SplitMode = ENSplitterSplitMode.OffsetFromNearSide
mainSplitter.SplitOffset = 370
mainSplitter.Pane1.Content = libraryPanSplitter
mainSplitter.Pane2.Content = m_DrawingView
' Create the ribbon UI
Dim builder As NDiagramRibbonBuilder = New NDiagramRibbonBuilder()
m_DrawingView.Document.HistoryService.Pause()
Try
InitDiagram(m_DrawingView.Document)
Finally
m_DrawingView.Document.HistoryService.Resume()
End Try
Return builder.CreateUI(mainSplitter, m_DrawingView)
End Function
Public Function CreateExampleControls() As NWidget
Dim stackPanel As NStackPanel = New NStackPanel()
Dim designer = NDesigner.GetDesigner(m_DrawingView.Content.Pages(0).Layers)
Dim editor = designer.CreateStandaloneEditor(m_DrawingView.Content.Pages(0).Layers)
stackPanel.Add(editor)
Return stackPanel
End Function
Public Function GetExampleDescription() As String
Return "
Demonstrates page layers. Layers provide a powerful way to organize and manage the visibility and editing of different page items within a page.
They allow you to segregate page items into different categories, which is particularly useful for handling complex diagrams.
Each shape can be assigned to multiple layers. In the example above, the Red shape is assigned to the Red layer, the Blue shape to the Blue layer, the Green shape to the Green layer,
and the Grey shape is assigned to all layers (Red, Green, and Blue).
Use the Layers editor on the right side to explore the behavior of the different layer properties.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Diagram Layers", "https://www.nevron.com/docs/openvision/diagram-layers.html"), ("Pages", "https://www.nevron.com/docs/openvision/diagram-pages.html")}
End Function
Private Sub InitDiagram(drawingDocument As NDrawingDocument)
Dim drawing = drawingDocument.Content
' hide the grid
drawing.ScreenVisibility.ShowGrid = False
' create several layers
Dim redLayer As NLayer = New NLayer()
redLayer.Color = NColor.Red
redLayer.Name = "Red"
drawing.ActivePage.Layers.Add(redLayer)
Dim greenLayer As NLayer = New NLayer()
greenLayer.Color = NColor.Green
greenLayer.Name = "Green"
drawing.ActivePage.Layers.Add(greenLayer)
Dim blueLayer As NLayer = New NLayer()
blueLayer.Name = "Blue"
blueLayer.Color = NColor.Blue
drawing.ActivePage.Layers.Add(blueLayer)
' create several shapes, each assigned to different layer(s)
Dim shapeFactory As NBasicShapeFactory = New NBasicShapeFactory()
Dim redShape = shapeFactory.CreateShape(ENBasicShape.Rectangle)
redShape.Text = "Red"
redShape.Geometry.Fill = New NColorFill(NColor.Red)
redShape.SetBounds(10, 10, 100, 100)
redShape.AssignToLayers(redLayer)
drawing.ActivePage.Items.Add(redShape)
Dim greenShape = shapeFactory.CreateShape(ENBasicShape.Rectangle)
greenShape.Text = "Green"
greenShape.Geometry.Fill = New NColorFill(NColor.Green)
greenShape.SetBounds(120, 10, 100, 100)
greenShape.AssignToLayers(greenLayer)
drawing.ActivePage.Items.Add(greenShape)
Dim blueShape = shapeFactory.CreateShape(ENBasicShape.Rectangle)
blueShape.Text = "Blue"
blueShape.Geometry.Fill = New NColorFill(NColor.Blue)
blueShape.SetBounds(230, 10, 100, 100)
blueShape.AssignToLayers(blueLayer)
drawing.ActivePage.Items.Add(blueShape)
Dim grayShape = shapeFactory.CreateShape(ENBasicShape.Rectangle)
grayShape.Text = "Red, Green and Blue"
grayShape.Geometry.Fill = New NColorFill(NColor.Gray)
grayShape.SetBounds(10, 120, 320, 100)
grayShape.AssignToLayers(redLayer, greenLayer, blueLayer)
drawing.ActivePage.Items.Add(grayShape)
End Sub
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
#End Region
#Region "Fields"
Private m_DrawingView As NDrawingView
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class