Add NOV Barcode control in MonoMac project at runtime

Add NOV Barcode 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 Barcode 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.Barcode.dll - assembly for the NBarcodeModule;

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

using System;
using Nevron.Nov;
using Nevron.Nov.Mac;
using Nevron.Nov.Barcode;
  
#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
                NBarcodeModule.Instance
            };
            NNOVApplicationInstaller.Install(modules);
  
            NSApplication.Main(args);
        }
    }
}

3. Create a Linear and Matrix (QR) Barcodes
Open the MainWindow.cs file and use the following code to create the Barcode:

using System;
 
using Nevron.Nov.Mac;
using Nevron.Nov.UI;
using Nevron.Nov;
using Nevron.Nov.Barcode;
using Nevron.Nov.Layout;
 
#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 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;
            qrCode.Text = "Nevron Software" + Environment.NewLine + "https://www.nevron.com";
            stackPanel.Add(qrCode);
 
            // create NOV host
            this.ContentView = new NNovWidgetHost(stackPanel);
        }
 
        #endregion
    }
}

Run the application - it should display a simple Mac window with a Linear and Matrix (QR) Barcodes.



For more information about the NOV Barcode component, take a look at the Help Documentation:
Barcodes > Barcodes Overview

 
Download Free Trial  Help Documentation
Send Feedback

Article ID: 266, Created On: 8/19/2016, Modified: 8/19/2016