Off Position using a Pin Example for WinForms

Off Position using a Pin Example for WinForms

Nevron NOV Gauge for WinForms ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WinForms Gauge examples are also available as a stand-alone Visual Studio solution in C# and VB.NET, which you can download from the links below.

Off Position using a Pin Example for WinForms Description

This example demonstrates how to use a minimum scale pin to define a pointer's off position.


Scales off Position Example

C# Off Position using a Pin Example Code for Nevron Gauge for WinForms
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NScalesOffPositionExample";

			// Create the NOV example and its controls
			NWidget exampleContent = CreateExampleContent();
			NWidget exampleControls = CreateExampleControls();
			if (exampleControls != null)
			{
				exampleControls.PreferredWidth = 300;
			}

			// Place the example and its controls in a pair box
			NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
			pairBox.FillMode = ENStackFillMode.First;
			pairBox.FitMode = ENStackFitMode.First;
			pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);

			// Host the example in the form
			NNovWidgetHost host = new NNovWidgetHost(pairBox);
			host.Dock = DockStyle.Fill;
			Controls.Add(host);
		}

		#endregion

        #region Example

        /// 
        /// 
        /// 
        /// 
        public NWidget CreateExampleContent()
        {
            NStackPanel stack = new NStackPanel();

            NStackPanel controlStack = new NStackPanel();
            controlStack.Padding = new NMargins(20);
            stack.Add(controlStack);

            // create the radial gauge
            m_RadialGauge = new NRadialGauge();
            m_RadialGauge.PreferredSize = defaultRadialGaugeSize;
            m_RadialGauge.NeedleCap.Visible = true;
            m_RadialGauge.NeedleCap.Size = new NSize(30, 30);

            m_RadialGauge.SweepAngle = new NAngle(270, NUnit.Degree);
            m_RadialGauge.BeginAngle = new NAngle(135, NUnit.Degree);

            controlStack.Add(m_RadialGauge);

            // add axis 
            NGaugeAxis axis = new NGaugeAxis();
            m_RadialGauge.Axes.Clear();
            m_RadialGauge.Axes.Add(axis);
            axis.Range = new NRange(-10, 100);
            axis.Anchor = new NDockGaugeAxisAnchor(ENGaugeAxisDockZone.Top, true, ENScaleOrientation.Left, 0.0f, 100.0f);

            // add scale
            m_Scale = (NLinearScale)axis.Scale;
            m_Scale.SetPredefinedScale(ENPredefinedScaleStyle.PresentationNoStroke);
            m_Scale.Labels.Style.TextStyle.Font = new NFont("Microsoft Sans Serif", 15, ENFontStyle.Bold);
            m_Scale.Labels.Style.TextStyle.Fill = new NColorFill(NColor.CornflowerBlue);
          
            m_Scale.MajorTickMode = ENMajorTickMode.CustomStep;
            m_Scale.CustomStep = 10;
            m_Scale.OuterMinorTicks.Visible = true;
            m_Scale.OuterMajorTicks.Length = 10;
            m_Scale.OuterMajorTicks.Width = 7;
            m_Scale.OuterMajorTicks.Fill = new NColorFill(NColor.CornflowerBlue);
            m_Scale.MinorTickCount = 5;
            m_Scale.OuterMinorTicks.Length = 4;
            m_Scale.OuterMinorTicks.Width = 3;
            m_Scale.OuterMinorTicks.Fill = new NColorFill(NColor.Gray);

            // create a custom label "Off"
            NCustomValueLabel label = new NCustomValueLabel(-10, "Off");
            label.LabelStyle.ZOrder = 1;
            m_Scale.CustomLabelOverlapResolveLayouts = new NDomArray(new ENLevelLabelsLayout[] { ENLevelLabelsLayout.RemoveOverlap });
            m_Scale.CreateNewLevelForCustomLabels = false;
            m_Scale.CustomLabels.Add(label);
        
            // needle value 
            m_NeedleIndicator = new NNeedleValueIndicator();
            m_NeedleIndicator.ScaleAxis = axis;
            m_NeedleIndicator.Fill = new NColorFill(NColor.CornflowerBlue);
            m_NeedleIndicator.EnableDampening = true;
            m_RadialGauge.Indicators.Add(m_NeedleIndicator);

            // Timer
            m_Timer = new NTimer();
            m_Timer.Interval = 200;
            m_Timer.Tick += OnTimerTick;
            m_Timer.Start();

            return stack;
        }
        /// 
        /// 
        /// 
        /// 
        public NWidget CreateExampleControls()
        {
            NStackPanel stack = new NStackPanel();

            NStackPanel propertyStack = new NStackPanel();
            stack.Add(new NUniSizeBoxGroup(propertyStack));

            NButton toggleTimerButton = new NButton("Turn off");
            toggleTimerButton.Click += OnToggleTimerButtonClick;
            toggleTimerButton.Tag = 1;
            stack.Add(toggleTimerButton);

            return stack;
        }

        public string GetExampleDescription()
        {
            return @"

This example demonstrates how to use a minimum scale pin to define a pointer's off position.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Gauges Axes", "https://www.nevron.com/docs/openvision/gauges-axes.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), ("Gauges Overview", "https://www.nevron.com/docs/openvision/gauges-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers private void OnToggleTimerButtonClick(NEventArgs arg) { NButton button = (NButton)arg.TargetNode; if ((int)button.Tag == 0) { m_Timer.Start(); button.Content = new NLabel("Turn On"); button.Tag = 1; } else { m_Timer.Stop(); button.Content = new NLabel("Turn Off"); button.Tag = 0; m_NeedleIndicator.Value = -10; } } private void OnTimerTick() { // update the indicator m_FirstIndicatorAngle += Math.PI / 180.0; double value = 50 + Math.Sin(m_FirstIndicatorAngle) * (20 + rand.Next(30)); m_NeedleIndicator.Value = value; } #endregion #region Fields NRadialGauge m_RadialGauge; NLinearScale m_Scale; NNeedleValueIndicator m_NeedleIndicator; NTimer m_Timer; private Random rand = new Random(); double m_FirstIndicatorAngle; #endregion #region Static Methods #endregion #region Constants private static readonly NSize defaultRadialGaugeSize = new NSize(300, 300); #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Off Position using a Pin Example for WinForms Solution

VB.NET Off Position using a Pin Example Code for Nevron Gauge for WinForms
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Chart
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Forms
Imports System

Public Class Form1

#Region "Constructors"

    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        ' Set form title
        Text = "NOV WinForms - NScalesOffPositionExample"

        ' Create the NOV example and its controls
        Dim exampleContent As NWidget = CreateExampleContent()
        Dim exampleControls As NWidget = CreateExampleControls()
        If Not exampleControls Is Nothing Then
            exampleControls.PreferredWidth = 300
        End If

        ' Place the example and its controls in a pair box
        Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
        pairBox.FillMode = ENStackFillMode.First
        pairBox.FitMode = ENStackFitMode.First
        pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)

        ' Host the example in the form
        Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
        host.Dock = DockStyle.Fill
        Controls.Add(host)
    End Sub


#End Region

#Region "Example"

        ''' 
        ''' 
        ''' 
        ''' 
        Public Function CreateExampleContent() As NWidget
            Dim stack As NStackPanel = New NStackPanel()

            Dim controlStack As NStackPanel = New NStackPanel()
            controlStack.Padding = New NMargins(20)
            stack.Add(controlStack)

            ' create the radial gauge
            m_RadialGauge = New NRadialGauge()
            m_RadialGauge.PreferredSize = defaultRadialGaugeSize
            m_RadialGauge.NeedleCap.Visible = True
            m_RadialGauge.NeedleCap.Size = New NSize(30, 30)

            m_RadialGauge.SweepAngle = New NAngle(270, NUnit.Degree)
            m_RadialGauge.BeginAngle = New NAngle(135, NUnit.Degree)

            controlStack.Add(m_RadialGauge)

            ' add axis 
            Dim axis As NGaugeAxis = New NGaugeAxis()
            m_RadialGauge.Axes.Clear()
            m_RadialGauge.Axes.Add(axis)
            axis.Range = New NRange(-10, 100)
            axis.Anchor = New NDockGaugeAxisAnchor(ENGaugeAxisDockZone.Top, True, ENScaleOrientation.Left, 0.0F, 100.0F)

            ' add scale
            m_Scale = CType(axis.Scale, NLinearScale)
            m_Scale.SetPredefinedScale(ENPredefinedScaleStyle.PresentationNoStroke)
            m_Scale.Labels.Style.TextStyle.Font = New NFont("Microsoft Sans Serif", 15, ENFontStyle.Bold)
            m_Scale.Labels.Style.TextStyle.Fill = New NColorFill(NColor.CornflowerBlue)

            m_Scale.MajorTickMode = ENMajorTickMode.CustomStep
            m_Scale.CustomStep = 10
            m_Scale.OuterMinorTicks.Visible = True
            m_Scale.OuterMajorTicks.Length = 10
            m_Scale.OuterMajorTicks.Width = 7
            m_Scale.OuterMajorTicks.Fill = New NColorFill(NColor.CornflowerBlue)
            m_Scale.MinorTickCount = 5
            m_Scale.OuterMinorTicks.Length = 4
            m_Scale.OuterMinorTicks.Width = 3
            m_Scale.OuterMinorTicks.Fill = New NColorFill(NColor.Gray)

            ' create a custom label "Off"
            Dim label As NCustomValueLabel = New NCustomValueLabel(-10, "Off")
            label.LabelStyle.ZOrder = 1
            m_Scale.CustomLabelOverlapResolveLayouts = New NDomArray(Of ENLevelLabelsLayout)(New ENLevelLabelsLayout() {ENLevelLabelsLayout.RemoveOverlap})
            m_Scale.CreateNewLevelForCustomLabels = False
            m_Scale.CustomLabels.Add(label)

            ' needle value 
            m_NeedleIndicator = New NNeedleValueIndicator()
            m_NeedleIndicator.ScaleAxis = axis
            m_NeedleIndicator.Fill = New NColorFill(NColor.CornflowerBlue)
            m_NeedleIndicator.EnableDampening = True
            m_RadialGauge.Indicators.Add(m_NeedleIndicator)

            ' Timer
            m_Timer = New NTimer()
            m_Timer.Interval = 200
            Me.m_Timer.Tick += AddressOf OnTimerTick
            m_Timer.Start()

            Return stack
        End Function
        ''' 
        ''' 
        ''' 
        ''' 
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()

            Dim propertyStack As NStackPanel = New NStackPanel()
            stack.Add(New NUniSizeBoxGroup(propertyStack))

            Dim toggleTimerButton As NButton = New NButton("Turn off")
            toggleTimerButton.Click += AddressOf OnToggleTimerButtonClick
            toggleTimerButton.Tag = 1
            stack.Add(toggleTimerButton)

            Return stack
        End Function

        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to use a minimum scale pin to define a pointer's off position.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Gauges Axes", "https://www.nevron.com/docs/openvision/gauges-axes.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), ("Gauges Overview", "https://www.nevron.com/docs/openvision/gauges-overview.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnToggleTimerButtonClick(arg As NEventArgs) Dim button = CType(arg.TargetNode, NButton) If CInt(button.Tag) = 0 Then m_Timer.Start() button.Content = New NLabel("Turn On") button.Tag = 1 Else m_Timer.Stop() button.Content = New NLabel("Turn Off") button.Tag = 0 m_NeedleIndicator.Value = -10 End If End Sub Private Sub OnTimerTick() ' update the indicator m_FirstIndicatorAngle += Math.PI / 180.0 Dim value = 50 + Math.Sin(m_FirstIndicatorAngle) * (20 + rand.Next(30)) m_NeedleIndicator.Value = value End Sub #End Region #Region "Fields" Private m_RadialGauge As NRadialGauge Private m_Scale As NLinearScale Private m_NeedleIndicator As NNeedleValueIndicator Private m_Timer As NTimer Private rand As Random = New Random() Private m_FirstIndicatorAngle As Double #End Region #Region "Static Methods" #End Region #Region "Constants" Private Shared ReadOnly defaultRadialGaugeSize As NSize = New NSize(300, 300) #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Off Position using a Pin Example for WinForms Solution