Nevron Open Vision Documentation
Getting Started / Integrating NOV in Windows Forms for C# and VB.NET
In This Topic
    Integrating NOV in Windows Forms for C# and VB.NET
    In This Topic

    There are 3 ways in which NOV NOVcan integrate in a Windows Forms application:

     Designer (Toolbox) Integration

    You can simply drag and drop NOV controls from the Visual Studio Toolbox. The Visual Studio Designer will automatically add the necessary dll references to your project and you can start coding directly. The following code snippet shows how to say "Hello World from Nevron Open Vision" using this type:

    1. Drag and Drop the NLabelControl from the "Nevron NOV Controls" toolbox category to the form.

    2. Write the following code in the Form Load event handler

    Setting NOV label's text
    Copy Code
    private void Form1_Load(object sender, EventArgs e)
    {
          nLabelControl1.Widget.Text = "Hello World from NOV";
    }
    

    That's it - you have created your first WinForms application using a NOV control. For more information check out the Integrating NOV from the Visual Studio Toolbox topic.

     Coded Integration for C# and VB.NET

    With this type of integration you write the code needed to add NOV components to the WinForms form. This approach allows you to create interfaces that can easily be ported to Mac. Another benefit from this approach is that you can create heavier interfaces (with many NOV controls).

    The steps to use in this case are:

    1. Create a new WinForm project in Visual Studio

    • From File Menu - Choose New Project
    • Select the "Visual C# -> Windows Forms App" or "Visual Basic -> Windows Forms App"
    • Click OK
    This step is not mandatory, because you can integrate NOV in an already existing WinForms 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 assembly.
    • Nevron.Nov.GraphicsGL.dll - NOV hardware accelerated 2D and 3D graphics engine.
    • Nevron.Nov.Host.WinBase.dll - base assembly for Windows presentation hosts (WinForm and WPF).
    • Nevron.Nov.Host.WinForm.dll - presentation host for WinForms.
    • Nevron.Nov.Barcode.dll - NOV Barcode.
    • Nevron.Nov.Chart.dll - NOV Chart.
    • Nevron.Nov.Diagram.dll - NOV Diagram.
    • Nevron.Nov.Grid.dll - NOV Grid.
    • Nevron.Nov.Schedule.dll - NOV Schedule.
    • Nevron.Nov.Text.dll - NOV Text.

    3. Initialize the NOV Application

    For C# projects 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.

    C# - Installing NOV for Windows Forms
    Copy Code
    using System;
    using System.Windows.Forms;
             
    using Nevron.Nov;
    using Nevron.Nov.Barcode;
    using Nevron.Nov.Chart;
    using Nevron.Nov.Diagram;
    using Nevron.Nov.Grid;
    using Nevron.Nov.Schedule;
    using Nevron.Nov.Text;
    using Nevron.Nov.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"));
    
                // GPU rendering is enabled by default. To disable GPU rendering uncomment the following line.
                // NApplication.EnableGPURendering = false;
    
                // Install NOV
                NModule[] modules = new NModule[] {
                    NBarcodeModule.Instance,
                    NChartModule.Instance,
                    NDiagramModule.Instance,
                    NGridModule.Instance,
                    NScheduleModule.Instance,
                    NTextModule.Instance
                };
    
                NNovApplicationInstaller.Install(modules);
                Application.Run(new Form1());
            }
        }
    }
    

    For Visual Basic projects open the file ApplicationEvents.vb and add a handler for the Application Startup like shown below. Note that if your VB.NET project does not target .NET 5.0 or newer, the ApplicationEvents.vb file might be missing. To add it, right-click the project in Solution Explorer, select "Properties" and click the "View Application Events" button.

    VB.NET - Installing NOV for Windows Forms
    Copy Code
    Imports Microsoft.VisualBasic.ApplicationServices
    Imports Nevron.Nov
    Imports Nevron.Nov.Barcode
    Imports Nevron.Nov.Chart
    Imports Nevron.Nov.Diagram
    Imports Nevron.Nov.Grid
    Imports Nevron.Nov.Schedule
    Imports Nevron.Nov.Text
    Imports Nevron.Nov.Windows.Forms
    
    Namespace My
        Partial Friend Class MyApplication
            Private Sub MyApplication_Startup(sender As Object, e As ApplicationServices.StartupEventArgs) Handles Me.Startup
                ' TODO: Apply license for redistribution here. You can skip this code when evaluating NOV.
                ' NLicenseManager.Instance.SetLicense(New NLicense("LICENSE KEY"))
    
                ' GPU rendering is enabled by default. To disable GPU rendering uncomment the following line.
                ' NApplication.EnableGPURendering = False
    
                ' Install Nevron Open Vision for Windows Forms
                NNovApplicationInstaller.Install(
                    NBarcodeModule.Instance,
                    NTextModule.Instance,
                    NChartModule.Instance,
                    NDiagramModule.Instance,
                    NScheduleModule.Instance,
                    NGridModule.Instance)
            End Sub
        End Class
    End Namespace
    

    After purchasing a license for NOV, you should uncomment the code that applies the license key and use a valid license key code (48 characters alpha-numeric key).

    4. Say Hello World from NOV

    For C# projects right-click the Form1.cs file in Solution Explorer, select "View Code" and replace its content with the following code:

    C# - Hello World from NOV
    Copy Code
    using System.Windows.Forms;
    using Nevron.Nov.UI;
    using Nevron.Nov.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));
            }
        }
    }
    

     For Visual Basic (VB.NET) project right-click the Form1.vb file in Solution Explorer, select "View Code" and and replace its content with the following code:

    VB.NET - Hello World from NOV
    Copy Code
    Imports Nevron.Nov
    Imports Nevron.Nov.UI
    Imports Nevron.Nov.Windows.Forms
    
    Public Class Form1
        Protected Overrides Sub OnLoad(e As EventArgs)
            MyBase.OnLoad(e)
    
            Dim host As New NNovWidgetHost(Of NWidget)(CreateNovContent())
            host.Dock = DockStyle.Fill
            Controls.Add(host)
        End Sub
    
        Private Function CreateNovContent() As NWidget
            Dim label As NLabel = New NLabel("Hello World from Nevron Open Vision")
            label.TextAlignment = ENContentAlignment.MiddleCenter
            Return label
        End Function
    End Class
    

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

    This is as much as is required to host some NOV content in Windows Forms. 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 UI Overview topic for an overview of the User Interface that comes along with NOV.

    See Also