Add NOV Diagram control in MonoMac project at runtime
To get started and host NOV in your Mac OS X (MonoMac) application, take a look at:
Getting Started with NOV in MonoMac project
The following topic shows how to add a NOV Diagram Widget (control) in MonoMac project 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.MonoMac.dll - presentation host for MonoMac;
MonoMac.dll - make sure to reference the MonoMac.dll that comes with the NOV installation and remove the default one, which is created by Xamarin Studio;
Nevron.Nov.Diagram.dll - assembly for the NDiagramModule;
You can reference the dlls directly from the System/Applications/NevronOpenVision.MonoMac.app/Contents/Bin folder or copy those dlls to a folder which is more convenient for referencing.
2. When initializing the NOV Application, make sure to create the Diagram module
Open the Main.cs file and use the following code:
using
System;
using
Nevron.Nov;
using
Nevron.Nov.Mac;
using
Nevron.Nov.Diagram;
#if UNIFIEDAPI
using
Foundation;
using
AppKit;
#else
using
MonoMac.Foundation;
using
MonoMac.AppKit;
#endif
namespace
MonoMacApplication1
{
class
MainClass
{
static
void
Main(
string
[] args)
{
NSApplication.Init();
NLicenseManager.Instance.SetLicense(
new
NLicense(
"LICENSE KEY"
));
// install NOV
NModule[] modules =
new
NModule[]
{
// TODO: Create modules here
NDiagramModule.Instance
};
NNOVApplicationInstaller.Install(modules);
NSApplication.Main(args);
}
}
}
3. Create the Diagram Drawing View, add two shapes and connect them
Open the MainWindow.cs file and use the following code to create the Diagram:
using
Nevron.Nov;
using
Nevron.Nov.Diagram;
using
Nevron.Nov.Diagram.Shapes;
#if UNIFIEDAPI
using
Foundation;
using
AppKit;
#else
using
MonoMac.Foundation;
using
MonoMac.AppKit;
#endif
namespace
MonoMacApplication1
{
public
partial
class
MainWindow : NSWindow
{
#region Constructors
// Called when created from unmanaged code
public
MainWindow(IntPtr handle)
:
base
(handle)
{
Initialize();
}
// Called when created directly from a XIB file
[Export(
"initWithCoder:"
)]
public
MainWindow(NSCoder coder)
:
base
(coder)
{
Initialize();
}
// Shared initialization code
void
Initialize()
{
NApplication.ApplyTheme(
new
NMacElCapitanTheme());
// 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
this
.ContentView =
new
NNovWidgetHost(drawingView);
}
#endregion
}
}
Run the application - it should display a simple Mac window with a Diagram.
For more information about the NOV Diagram component, take a look at the Help Documentation:
Diagram > Diagram Overview
Article ID: 257, Created On: 8/16/2016, Modified: 8/16/2016