Add NOV Gauge control in WPF at runtime
To get started and host NOV in your WPF application, take a look at:
Getting Started with NOV in WPF using only code
The following topic shows how to add a NOV Gauge Widget (control) in WPF 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.Wpf.dll - presentation host for WPF;
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.Windows;
using
Nevron.Nov.Chart;
using
System;
namespace
WpfApplication1
{
static
class
Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static
void
Main()
{
// create the application
App app =
new
App();
// Apply license for redistribution here. You can skip this code when evaluating NOV.
NLicenseManager.Instance.SetLicense(
new
NLicense(
"LICENSE KEY"
));
NModule[] modules =
new
NModule[] {
// TODO: Create modules here
NChartModule.Instance
};
// install Nevron Open Vision for WPF
NNovApplicationInstaller.Install(modules);
// run the application main window
app.Run(
new
MainWindow());
}
}
}
3. Create the Radial Gauge and add needle and range indicators
Open the MainWindow.xaml.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;
using
System.Windows;
namespace
WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public
partial
class
MainWindow : Window
{
public
MainWindow()
{
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);
Content = host;
}
}
}
Run the application - it should display a simple window with a Radial Gauge.
Using Visual Basic .NET (VB.NET)
When you create a Visual Basic WPF Application, reference the NOV Assemblies and use the following code in your MainWindow.xaml.vb:
Imports
Nevron.Nov
Imports
Nevron.Nov.Chart
Imports
Nevron.Nov.Graphics
Imports
Nevron.Nov.Windows
Partial
Public
Class
MainWindow
Inherits
Window
Public
Sub
New
()
InitializeComponent()
' clear all controls from the form
' 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
Content =
New
NNovWidgetHost(Of NRadialGauge)(radialGauge)
End
Sub
End
Class
For more information about the NOV Gauge component, take a look at the Help Documentation:
Instrumentation > Instrumentation Overview
Article ID: 259, Created On: 8/16/2016, Modified: 9/27/2016