Add NOV Rich Text Editor 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 Rich Text Editor 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.Text.dll - assembly for the NTextModule;
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 Text module
Open the Main.cs file and use the following code:
using
System;
using
Nevron.Nov;
using
Nevron.Nov.Mac;
using
Nevron.Nov.Text;
#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
NTextModule.Instance
};
NNOVApplicationInstaller.Install(modules);
NSApplication.Main(args);
}
}
}
3. Create the Rich Text View and say Hello World
We will create a Rich Text View, a Document Block and a Section. We will then say "Hello World" in a new paragraph.
Open the MainWindow.cs file and use the following code to create the Rich Text View:
using
System;
using
Nevron.Nov.Mac;
using
Nevron.Nov.UI;
using
Nevron.Nov;
using
Nevron.Nov.Text;
#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 the rich text
NRichTextView richText =
new
NRichTextView();
// create document block
NDocumentBlock documentBlock = richText.Content;
documentBlock.Layout = ENTextLayout.Web;
documentBlock.Sections.Clear();
// create section and paragraph saying Hello World
NSection section =
new
NSection();
section.Blocks.Add(
new
NParagraph(
"Hello World"
));
documentBlock.Sections.Add(section);
// create NOV host
this
.ContentView =
new
NNovWidgetHost(richText);
}
#endregion
}
}
Run the application - it should display a simple Mac window with a Rich Text Editor.
For more information about the NOV Rich Text Editor component, take a look at the Help Documentation:
Rich Text Editor > Rich Text Editor Overview
Article ID: 254, Created On: 8/12/2016, Modified: 8/12/2016