Add NOV Gauge control in WinForms at runtime

Add NOV Gauge 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 Gauge 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.Chart.dll - assembly for the NChartModule;

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

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

3. Create the Radial Gauge and add needle and range indicators
Open the Form1.cs file and use the following code to create the Gauge:

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Graphics;
using Nevron.Nov.Windows.Forms;
using System.Windows.Forms;
 
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
 
            // Set window size
            this.Width = 620;
            this.Height = 300;
 
            // Creat a radial gauge
            NRadialGauge radialGauge = new NRadialGauge();
            radialGauge.SweepAngle = new NAngle(320, NUnit.Degree);
            radialGauge.BeginAngle = new NAngle(110, NUnit.Degree);
            radialGauge.Margins = new NMargins(10);
 
            radialGauge.CapEffect = new NGlassCapEffect();
            radialGauge.Dial = new NDial(ENDialShape.CutCircle, new NEdgeDialRim());
            radialGauge.Dial.BackgroundFill = new NStockGradientFill(NColor.DarkGray, NColor.Black);
 
            // Configure the gauge cap
            radialGauge.NeedleCap.Size = new NSize(30, 30);
            radialGauge.NeedleCap.Fill = new NStockGradientFill(ENGradientStyle.DiagonalUp, ENGradientVariant.Variant1, NColor.DarkGray, NColor.White);
            radialGauge.NeedleCap.Stroke.Width = 1;
            radialGauge.NeedleCap.Stroke.Color = NColor.DarkGray;
 
            // Create the gauge axis and configure the scale
            NGaugeAxis axis = new NGaugeAxis();
            radialGauge.Axes.Add(axis);
 
            NLinearScale scale = (NLinearScale)axis.Scale;
            scale.SetPredefinedScale(ENPredefinedScaleStyle.Presentation);
            scale.Labels.Style.TextStyle.Font = new NFont("Arimo", 10, ENFontStyle.Bold);
            scale.Labels.Style.TextStyle.Fill = new NColorFill(NColor.White);
            scale.MinorTickCount = 4;
            scale.Ruler.Stroke.Width = 0;
            scale.Ruler.Fill = new NColorFill(NColor.DarkGray);
 
            // Add needle indicator
            NNeedleValueIndicator valueIndicator = new NNeedleValueIndicator();
            valueIndicator.Fill = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, NColor.White, NColor.Red);
            valueIndicator.Stroke.Color = NColor.Red;
            valueIndicator.Value = 55;
            valueIndicator.Width = 15;
            valueIndicator.OffsetFromScale = -10;
            radialGauge.Indicators.Add(valueIndicator);
 
            // Add range indicator
            NRangeIndicator rangeIndicator = new NRangeIndicator();
            rangeIndicator.PaintOrder = ENIndicatorPaintOrder.BeforeScale;
            rangeIndicator.Value = 100;
            rangeIndicator.BeginWidth = 5;
            rangeIndicator.EndWidth = 20;
            rangeIndicator.Stroke.Width = 0;
            rangeIndicator.Palette = new NTwoColorPalette(NColor.Green, NColor.Red);
            radialGauge.Indicators.Add(rangeIndicator);
 
            // Create NOV host
            NNovWidgetHost<NRadialGauge> host = new NNovWidgetHost<NRadialGauge>(radialGauge);
            host.Dock = DockStyle.Fill;
            Controls.Add(host);
        }
    }
}

Run the application - it should display a simple form with a Radial Gauge.




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
Imports Nevron.Nov.Windows.Forms
Imports Nevron.Nov.Chart
Imports Nevron.Nov.Graphics
 
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 = {NChartModule.Instance}
        NNovApplicationInstaller.Install(modules)
 
        ' Set window size
        Me.Width = 620
        Me.Height = 300
 
        ' Creat a radial gauge
        Dim radialGauge As New NRadialGauge()
        radialGauge.SweepAngle = New NAngle(320, NUnit.Degree)
        radialGauge.BeginAngle = New NAngle(110, NUnit.Degree)
        radialGauge.Margins = New NMargins(10)
 
        radialGauge.CapEffect = New NGlassCapEffect()
        radialGauge.Dial = New NDial(ENDialShape.CutCircle, New NEdgeDialRim())
        radialGauge.Dial.BackgroundFill = New NStockGradientFill(NColor.DarkGray, NColor.Black)
 
        ' Configure the gauge cap
        radialGauge.NeedleCap.Size = New NSize(30, 30)
        radialGauge.NeedleCap.Fill = New NStockGradientFill(ENGradientStyle.DiagonalUp, ENGradientVariant.Variant1, NColor.DarkGray, NColor.White)
        radialGauge.NeedleCap.Stroke.Width = 1
        radialGauge.NeedleCap.Stroke.Color = NColor.DarkGray
 
        ' Create the gauge axis and configure the scale
        Dim axis As New NGaugeAxis()
        radialGauge.Axes.Add(axis)
 
        Dim scale As NLinearScale = DirectCast(axis.Scale, NLinearScale)
        scale.SetPredefinedScale(ENPredefinedScaleStyle.Presentation)
        scale.Labels.Style.TextStyle.Font = New NFont("Arimo", 10, ENFontStyle.Bold)
        scale.Labels.Style.TextStyle.Fill = New NColorFill(NColor.White)
        scale.MinorTickCount = 4
        scale.Ruler.Stroke.Width = 0
        scale.Ruler.Fill = New NColorFill(NColor.DarkGray)
 
        ' Add needle indicator
        Dim valueIndicator As New NNeedleValueIndicator()
        valueIndicator.Fill = New NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, NColor.White, NColor.Red)
        valueIndicator.Stroke.Color = NColor.Red
        valueIndicator.Value = 55
        valueIndicator.Width = 15
        valueIndicator.OffsetFromScale = -10
        radialGauge.Indicators.Add(valueIndicator)
 
        ' Add range indicator
        Dim rangeIndicator As New NRangeIndicator()
        rangeIndicator.PaintOrder = ENIndicatorPaintOrder.BeforeScale
        rangeIndicator.Value = 100
        rangeIndicator.BeginWidth = 5
        rangeIndicator.EndWidth = 20
        rangeIndicator.Stroke.Width = 0
        rangeIndicator.Palette = New NTwoColorPalette(NColor.Green, NColor.Red)
        radialGauge.Indicators.Add(rangeIndicator)
 
        ' Create the host widget
        Dim host As New NNovWidgetHost(Of NRadialGauge)(radialGauge)
        host.Dock = DockStyle.Fill
 
        ' add the host in the form controls
        Controls.Add(host)
    End Sub
End Class


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

 
Download Free Trial  Help Documentation
Send Feedback

Article ID: 258, Created On: 8/16/2016, Modified: 9/27/2016