Add NOV Gauge 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 Gauge 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.Chart.dll - assembly for the NChartModule;
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 Chart module
Open the Main.cs file and use the following code:
using
System;
using
Nevron.Nov;
using
Nevron.Nov.Mac;
using
Nevron.Nov.Chart;
#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
NChartModule.Instance
};
NNOVApplicationInstaller.Install(modules);
NSApplication.Main(args);
}
}
}
3. Create the Radial Gauge and add needle and range indicators
Open the MainWindow.cs file and use the following code to create the Gauge:
using
System;
using
Nevron.Nov.Mac;
using
Nevron.Nov.UI;
using
Nevron.Nov;
using
Nevron.Nov.Chart;
using
Nevron.Nov.Graphics;
#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());
// 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
this
.ContentView =
new
NNovWidgetHost(radialGauge);
}
#endregion
}
}
Run the application - it should display a simple Mac window with a Radial Gauge.
For more information about the NOV Gauge component, take a look at the Help Documentation:
Instrumentation > Instrumentation Overview
Article ID: 260, Created On: 8/16/2016, Modified: 8/16/2016