Getting Started with NOV in WinForms using only code

Getting Started with NOV in WinForms using only code



1. Create a new WinForms project in Visual Studio
  • From File Menu - Choose New Project
  • Select the Visual C# - Windows Forms Application Template
  • Click OK



This step is not mandatory, because you can integrate NOV in an already existing WinForm project. It is performed just for the purpose of making a complete installation scenario.

2. 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;




These assemblies are located in NOV installation folder: C:\Program Files (x86)\Nevron Software\Nevron Open Vision VERSION\Bin\Win

3. Initialize the NOV Application
Open the Program.cs file and ensure that the NNovApplicationInstaller.Install() method is called before the WinForm application runs the main form of the application.

using Nevron.Nov;
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
            };
            NNovApplicationInstaller.Install(modules);
            Application.Run(new Form1());
        }
    }
}


4. Say Hello World from NOV
Open the Form1.cs file and replace its content with the following code:

using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            // clear all controls from the form
            Controls.Clear();
            // Add a NOV widget inside the form
            NLabel sayHelloWorld = new NLabel("Hello World from Nevron Open Vision");
            Controls.Add(new NNovWidgetHost<NLabel>(sayHelloWorld));
        }
    }
}

Run the application - it should display a simple form with a "Hello World from Nevron Open Vision" label inside.




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.UI
Imports Nevron.Nov.Windows.Forms
Imports Nevron.Nov
 
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 = {}
        NNovApplicationInstaller.Install(modules)
 
        ' Add a NOV widget inside the form
        Dim sayHelloWorld As New NLabel("Hello World from Nevron Open Vision")
 
        ' create the host widget
        Dim host As New NNovWidgetHost(Of NLabel)(sayHelloWorld)
        host.Dock = DockStyle.Fill
 
        ' add the host in the form controls
        Controls.Add(host)
    End Sub
End Class


This is as much as is required to host some NOV content in Windows Forms. From now on you can forget everything you know about Windows Forms, since you will not need it when developing with NOV.

The sample just makes a simple label, as content of the NNovWidgetHost WinForms Control, but this control can actually contain any NOV widget. See the NOV Help Documentation -> UI Overview topic for an overview of the User Interface that comes along with NOV.

 
Download Free Trial  Help Documentation
Send Feedback

Article ID: 239, Created On: 7/22/2016, Modified: 9/27/2016