Add NOV Diagram control in WinForms at runtime
To get started and host NOV in your WinForms application, take a look at:
Getting Started with NOV in WinForms using only code
The following topic shows how to add a NOV Diagram Widget (control) in
WinForms at runtime.
1. Reference the NOV Assemblies
Ensure that your application references the following NOV dlls:
Nevron.Nov.Presentation.dll - core NOV portable assembly;
Nevron.Nov.Host.WinBase.dll - base assembly for Windows presentation hosts (WinForm and WPF);
Nevron.Nov.Host.WinForm.dll - presentation host for Window Forms;
Nevron.Nov.Diagram.dll - assembly for the NDiagramModule;
These assemblies are located in NOV installation folder: C:\Program Files (x86)\Nevron Software\Nevron Open Vision VERSION\Bin\Win
2. When initializing the NOV Application, make sure to create the Diagram module
Open the Program.cs file and use the following code:
using
Nevron.Nov;
using
Nevron.Nov.Diagram;
using
Nevron.Nov.Windows.Forms;
using
System;
using
System.Windows.Forms;
namespace
WindowsFormsApplication1
{
static
class
Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static
void
Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(
false
);
// Apply license for redistribution here. You can skip this code when evaluating NOV.
NLicenseManager.Instance.SetLicense(
new
NLicense(
"LICENSE KEY"
));
// Install NOV
NModule[] modules =
new
NModule[] {
// TODO: Create modules here
NDiagramModule.Instance
};
NNovApplicationInstaller.Install(modules);
Application.Run(
new
Form1());
}
}
}
3. Create the Diagram Drawing View, add two shapes and connect them
Open the Form1.cs file and use the following code to create the Diagram:
using
Nevron.Nov.Diagram;
using
Nevron.Nov.Diagram.Shapes;
using
Nevron.Nov.Windows.Forms;
using
System.Windows.Forms;
namespace
WindowsFormsApplication1
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
// Set window size
this
.Width = 620;
this
.Height = 300;
// Create a drawing view
NDrawingView drawingView =
new
NDrawingView();
// Get the drawing view document and its active page
NDrawingDocument document = drawingView.Document;
NPage activePage = document.Content.ActivePage;
// Create a rectange shape to the active page items
NBasicShapesFactory factory =
new
NBasicShapesFactory();
NShape rectangleShape = factory.CreateShape(ENBasicShapes.Rectangle);
rectangleShape.Text =
"My First Shape"
;
rectangleShape.SetBounds(25, 25, 100, 100);
activePage.Items.Add(rectangleShape);
// Create a rect with corner rounding
NShape roundRectShape = factory.CreateShape(ENBasicShapes.Rectangle);
roundRectShape.Text =
"My Rounded Rect Shape"
;
roundRectShape.Geometry.CornerRounding = 10;
roundRectShape.SetBounds(400, 80, 100, 100);
activePage.Items.Add(roundRectShape);
// Create a rounded routable connector
NConnectorShapesFactory connectorFactory =
new
NConnectorShapesFactory();
NShape connector = connectorFactory.CreateShape(ENConnectorShapes.RoutableConnector);
connector.Geometry.CornerRounding = 20;
connector.GlueBeginToShape(rectangleShape);
connector.GlueEndToShape(roundRectShape);
activePage.Items.Add(connector);
// Create NOV host
NNovWidgetHost<NDrawingView> host =
new
NNovWidgetHost<NDrawingView>(drawingView);
host.Dock = DockStyle.Fill;
Controls.Add(host);
}
}
}
Run the application - it should display a simple form with a Diagram.
Using Visual Basic .NET (VB.NET)
When you create a Visual Basic Windows Forms Application, reference the NOV Assemblies and use the following code in your Form1.vb:
Imports
Nevron.Nov
Imports
Nevron.Nov.Windows.Forms
Imports
Nevron.Nov.Diagram
Imports
Nevron.Nov.Diagram.Shapes
Public
Class
Form1
Inherits
Form
Public
Sub
New
()
InitializeComponent()
' clear all controls from the form
Controls.Clear()
' TODO: Apply license for redistribution here. You can skip this code when evaluating NOV.
NLicenseManager.Instance.SetLicense(
New
NLicense(
"LICENSE KEY"
))
' Install Nevron Open Vision modules
Dim
modules()
As
NModule = {NDiagramModule.Instance}
NNovApplicationInstaller.Install(modules)
' Set window size
Me
.Width = 620
Me
.Height = 300
' Create a drawing view
Dim
drawingView
As
New
NDrawingView()
' Get the drawing view document and its active page
Dim
document
As
NDrawingDocument = drawingView.Document
Dim
activePage
As
NPage = document.Content.ActivePage
' Create a rectange shape to the active page items
Dim
factory
As
New
NBasicShapesFactory()
Dim
rectangleShape
As
NShape = factory.CreateShape(ENBasicShapes.Rectangle)
rectangleShape.Text =
"My First Shape"
rectangleShape.SetBounds(25, 25, 100, 100)
activePage.Items.Add(rectangleShape)
' Create a rect with corner rounding
Dim
roundRectShape
As
NShape = factory.CreateShape(ENBasicShapes.Rectangle)
roundRectShape.Text =
"My Rounded Rect Shape"
roundRectShape.Geometry.CornerRounding = 10
roundRectShape.SetBounds(400, 80, 100, 100)
activePage.Items.Add(roundRectShape)
' Create a rounded routable connector
Dim
connectorFactory
As
New
NConnectorShapesFactory()
Dim
connector
As
NShape = connectorFactory.CreateShape(ENConnectorShapes.RoutableConnector)
connector.Geometry.CornerRounding = 20
connector.GlueBeginToShape(rectangleShape)
connector.GlueEndToShape(roundRectShape)
activePage.Items.Add(connector)
' Create the host widget
Dim
host
As
New
NNovWidgetHost(Of NDrawingView)(drawingView)
host.Dock = DockStyle.Fill
' add the host in the form controls
Controls.Add(host)
End
Sub
End
Class
For more information about the NOV Diagram component, take a look at the Help Documentation:
Diagram > Diagram Overview
Article ID: 255, Created On: 8/16/2016, Modified: 9/27/2016