Add NOV Rich Text Editor control in WPF at runtime

Add NOV Chart control in WPF at runtime



To get started and host NOV in your WPF application, take a look at: Getting Started with NOV in WPF using only code

The following topic shows how to add a NOV Rich Text Editor Widget (control) in WPF 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.Wpf.dll - presentation host for WPF;
Nevron.Nov.Text.dll - assembly for the NTextModule;

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 Text module
Open the Program.cs file and use the following code:

using Nevron.Nov;
using Nevron.Nov.Windows;
using Nevron.Nov.Text;
using System;
 
namespace WpfApplication1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            // create the application
            App app = new App();
 
            // Apply license for redistribution here. You can skip this code when evaluating NOV.
            NLicenseManager.Instance.SetLicense(new NLicense("LICENSE KEY"));
             
            NModule[] modules = new NModule[] {
                  // TODO: Create modules here
                  NTextModule.Instance
            };
            // install Nevron Open Vision for WPF
            NNovApplicationInstaller.Install(modules);
            // run the application main window
            app.Run(new MainWindow());
        }
    }
}

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.xaml.cs file and use the following code to create the Rich Text View:

using Nevron.Nov.Text;
using Nevron.Nov.Windows;
using System.Windows;
 
namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
 
            // Set window size
            this.Width = 620;
            this.Height = 300;
 
            // 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
            NNovWidgetHost<NRichTextView> host = new NNovWidgetHost<NRichTextView>(richText);
            Content = host;
        }       
    }
}

Run the application - it should display a simple window with a Rich Text Editor.




Using Visual Basic .NET (VB.NET)
When you create a Visual Basic WPF Application, reference the NOV Assemblies and use the following code in your MainWindow.xaml.vb:

Imports Nevron.Nov
Imports Nevron.Nov.Text
Imports Nevron.Nov.Windows
 
Partial Public Class MainWindow
    Inherits Window
    Public Sub New()
        InitializeComponent()
        ' clear all controls from the form
 
        ' 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 = {NTextModule.Instance}
        NNovApplicationInstaller.Install(modules)
 
        ' Set window size
        Me.Width = 620
        Me.Height = 300
 
        ' create the rich text
        Dim richText As New NRichTextView()
 
        '  create document block     
        Dim documentBlock As NDocumentBlock = richText.Content
        documentBlock.Layout = ENTextLayout.Web
 
        documentBlock.Sections.Clear()
 
        ' create section and paragraph saying Hello World
        Dim section As New NSection()
        section.Blocks.Add(New NParagraph("Hello World"))
 
        documentBlock.Sections.Add(section)
 
        ' create the host widget
        Content = New NNovWidgetHost(Of NRichTextView)(richText)
    End Sub
End Class


For more information about the NOV Rich Text Editor component, take a look at the Help Documentation:
Rich Text Editor > Rich Text Editor Overview

 
Download Free Trial  Help Documentation
Send Feedback

Article ID: 253, Created On: 8/12/2016, Modified: 9/27/2016