Add NOV Barcode control in WinForms at runtime
To get started and host NOV in your WinForms application, take a look at:
Getting Started with NOV in WinForms using only code
The following topic shows how to add a NOV Barcode Widget (control) in
WinForms 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.WinForm.dll - presentation host for Window Forms;
Nevron.Nov.Barcode.dll - assembly for the NBarcodeModule;
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 Barcode module
Open the Program.cs file and use the following code:
using
Nevron.Nov;
using
Nevron.Nov.Windows.Forms;
using
Nevron.Nov.Barcode;
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
NBarcodeModule.Instance
};
NNovApplicationInstaller.Install(modules);
Application.Run(
new
Form1());
}
}
}
3. Create a Linear and Matrix (QR) Barcodes
Open the Form1.cs file and use the following code to create the Barcode:
using
Nevron.Nov.Barcode;
using
Nevron.Nov.Layout;
using
Nevron.Nov.UI;
using
Nevron.Nov.Windows.Forms;
using
System;
using
System.Windows.Forms;
namespace
WindowsFormsApplication1
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
// Set window size
this
.Width = 620;
this
.Height = 300;
// create a stack panel
NStackPanel stackPanel =
new
NStackPanel();
stackPanel.Margins =
new
Nevron.Nov.Graphics.NMargins(5);
stackPanel.HorizontalPlacement = ENHorizontalPlacement.Left;
stackPanel.VerticalPlacement = ENVerticalPlacement.Top;
stackPanel.HorizontalSpacing = 5;
stackPanel.VerticalSpacing = 5;
// create linear barcode
NLinearBarcode barcode =
new
NLinearBarcode();
barcode.HorizontalPlacement = ENHorizontalPlacement.Center;
barcode.VerticalPlacement = ENVerticalPlacement.Center;
barcode.Text =
"Nevron software"
;
barcode.PreferredHeight = 100;
barcode.Symbology = ENLinearBarcodeSymbology.Code128;
stackPanel.Add(barcode);
// create matrix barcode
NMatrixBarcode qrCode =
new
NMatrixBarcode();
qrCode.Symbology = ENMatrixBarcodeSymbology.QrCode;
stackPanel.Add(qrCode);
// Create NOV host
NNovWidgetHost<NStackPanel> host =
new
NNovWidgetHost<NStackPanel>(stackPanel);
host.Dock = DockStyle.Fill;
Controls.Add(host);
}
}
}
Run the application - it should display a simple form with a Linear and Matrix (QR) Barcodes.
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.Barcode
Imports
Nevron.Nov.UI
Imports
Nevron.Nov.Layout
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 = {NBarcodeModule.Instance}
NNovApplicationInstaller.Install(modules)
' Set window size
Me
.Width = 620
Me
.Height = 300
' create a stack panel
Dim
stackPanel
As
New
NStackPanel()
stackPanel.Margins =
New
Nevron.Nov.Graphics.NMargins(5)
stackPanel.HorizontalPlacement = ENHorizontalPlacement.Left
stackPanel.VerticalPlacement = ENVerticalPlacement.Top
stackPanel.HorizontalSpacing = 5
stackPanel.VerticalSpacing = 5
' create linear barcode
Dim
barcode
As
New
NLinearBarcode()
barcode.HorizontalPlacement = ENHorizontalPlacement.Center
barcode.VerticalPlacement = ENVerticalPlacement.Center
barcode.Text =
"Nevron software"
barcode.PreferredHeight = 100
barcode.Symbology = ENLinearBarcodeSymbology.Code128
stackPanel.Add(barcode)
' create matrix barcode
Dim
qrCode
As
New
NMatrixBarcode()
qrCode.Symbology = ENMatrixBarcodeSymbology.QrCode
stackPanel.Add(qrCode)
' Create the host widget
Dim
host
As
New
NNovWidgetHost(Of NStackPanel)(stackPanel)
host.Dock = DockStyle.Fill
' add the host in the form controls
Controls.Add(host)
End
Sub
End
Class
For more information about the NOV Barcode component, take a look at the Help Documentation:
Barcodes > Barcodes Overview
Article ID: 264, Created On: 8/19/2016, Modified: 9/27/2016