Auto Adjusting Scale Example for WinForms

Auto Adjusting Scale 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.

Auto Adjusting Scale Example for WinForms Description


Auto Adjust Scale Example

C# Auto Adjusting Scale 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 - NAutoAdjustScaleExample";

			// 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();
            stack.Add(controlStack);

            // create the radial gauge
            m_RadialGauge = new NRadialGauge();
            m_RadialGauge.PreferredSize = defaultRadialGaugeSize;
            controlStack.Add(m_RadialGauge);

            m_RadialGauge.Dial = new NDial(ENDialShape.Circle, new NEdgeDialRim());
            m_RadialGauge.Dial.BackgroundFill = new NStockGradientFill(NColor.Black, NColor.Gray);

            NGelCapEffect gelEffect = new NGelCapEffect(ENCapEffectShape.Ellipse);
            gelEffect.Margins = new NMargins(0, 0, 0, 0.5);

            m_RadialGauge.Axes.Clear();

            // create the radial gauge
            m_RadialGauge.SweepAngle = new NAngle(180, NUnit.Degree);
            m_RadialGauge.BeginAngle = new NAngle(32, NUnit.Degree);

            // create the first axis
            NGaugeAxis axis1 = new NGaugeAxis();
            axis1.Anchor = new NDockGaugeAxisAnchor(ENGaugeAxisDockZone.Top, true, 30,180);
            
            m_RadialGauge.Axes.Add(axis1);

            //Cache the initial begin and end
            m_CurBegin = m_RadialGauge.Axes[0].Range.Begin;
            m_CurEnd = m_RadialGauge.Axes[0].Range.End;

            m_InitBegin =  m_CurBegin;
            m_InitEnd = m_CurEnd;

            // scale 
            m_Scale = (NStandardScale)axis1.Scale;
            m_Scale.SetPredefinedScale(ENPredefinedScaleStyle.PresentationNoStroke);
            m_Scale.MajorTickMode = ENMajorTickMode.AutoMaxCount;
            m_Scale.MaxTickCount = 9;
            m_Scale.MinorTickCount = 3;
            m_Scale.Ruler.Fill = new NColorFill(NColor.FromColor(NColor.White, 0.4f));
            m_Scale.OuterMajorTicks.Fill = new NColorFill(NColor.Orange);            
            m_Scale.Labels.Style.TextStyle.Font = new NFont("Arimo", 12, ENFontStyle.Bold);
            m_Scale.Labels.Style.TextStyle.Fill = new NColorFill(NColor.White);
            m_Scale.Labels.Style.Angle = new NScaleLabelAngle(ENScaleLabelAngleMode.Scale, 0);
            m_Scale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None;

            // Value Indicator
            m_NeedleValueIndicator = new NNeedleValueIndicator();
            m_NeedleValueIndicator.Fill = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, NColor.White, NColor.Red);
            m_NeedleValueIndicator.Stroke.Color = NColor.Red;
            m_NeedleValueIndicator.OffsetFromScale = 2;
            m_NeedleValueIndicator.Shape = ENNeedleShape.Triangle;
            m_RadialGauge.SweepAngle = new NAngle(360, NUnit.Degree);

            m_RadialGauge.Indicators.Add(m_NeedleValueIndicator);

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

            m_Range = 100;

            // radio buttons
            m_StepAndRotateScaleRadioButton = new NRadioButton("Step and Rotate Scale");
            m_ContinuouslyRotateRadioButton = new NRadioButton("Continuously Rotate");
            m_ContinuouslyRotateRadioButton.Checked = true;

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

            NRadioButtonGroup dynamicScaleRotationStylesGroup = new NRadioButtonGroup(stack);
            dynamicScaleRotationStylesGroup.SelectedIndex = 0;
            
            stack.Add(m_StepAndRotateScaleRadioButton);
            stack.Add(m_ContinuouslyRotateRadioButton);

            return dynamicScaleRotationStylesGroup;
        }
        /// 
        /// 
        /// 
        /// 
        public string GetExampleDescription()
        {
            return @"

"; } /// /// 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 #endregion #region Fields NRadialGauge m_RadialGauge; NNeedleValueIndicator m_NeedleValueIndicator; NStandardScale m_Scale; NTimer m_Timer; NRadioButton m_StepAndRotateScaleRadioButton; NRadioButton m_ContinuouslyRotateRadioButton; #endregion #region Static Methods #endregion #region Constants private static readonly NSize defaultRadialGaugeSize = new NSize(300, 300); private Random rand = new Random(); private double m_CurBegin; private double m_CurEnd; private double m_InitBegin; private double m_InitEnd; double m_Range; double m_FirstIndicatorAngle; const double c_ScaleRange = 50; const double c_RotateIncrement = 2; bool m_Increase = true; int m_Direction = 1; bool m_MoveRange = false; #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Auto Adjusting Scale Example for WinForms Solution

VB.NET Auto Adjusting Scale 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 - NAutoAdjustScaleExample"

        ' 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()
            stack.Add(controlStack)

            ' create the radial gauge
            m_RadialGauge = New NRadialGauge()
            m_RadialGauge.PreferredSize = defaultRadialGaugeSize
            controlStack.Add(m_RadialGauge)

            m_RadialGauge.Dial = New NDial(ENDialShape.Circle, New NEdgeDialRim())
            m_RadialGauge.Dial.BackgroundFill = New NStockGradientFill(NColor.Black, NColor.Gray)

            Dim gelEffect As NGelCapEffect = New NGelCapEffect(ENCapEffectShape.Ellipse)
            gelEffect.Margins = New NMargins(0, 0, 0, 0.5)

            m_RadialGauge.Axes.Clear()

            ' create the radial gauge
            m_RadialGauge.SweepAngle = New NAngle(180, NUnit.Degree)
            m_RadialGauge.BeginAngle = New NAngle(32, NUnit.Degree)

            ' create the first axis
            Dim axis1 As NGaugeAxis = New NGaugeAxis()
            axis1.Anchor = New NDockGaugeAxisAnchor(ENGaugeAxisDockZone.Top, True, 30, 180)

            m_RadialGauge.Axes.Add(axis1)

            'Cache the initial begin and end
            m_CurBegin = m_RadialGauge.Axes(CInt(0)).Range.Begin
            m_CurEnd = m_RadialGauge.Axes(CInt(0)).Range.End

            m_InitBegin = m_CurBegin
            m_InitEnd = m_CurEnd

            ' scale 
            m_Scale = CType(axis1.Scale, NStandardScale)
            m_Scale.SetPredefinedScale(ENPredefinedScaleStyle.PresentationNoStroke)
            m_Scale.MajorTickMode = ENMajorTickMode.AutoMaxCount
            m_Scale.MaxTickCount = 9
            m_Scale.MinorTickCount = 3
            m_Scale.Ruler.Fill = New NColorFill(NColor.FromColor(NColor.White, 0.4F))
            m_Scale.OuterMajorTicks.Fill = New NColorFill(NColor.Orange)
            m_Scale.Labels.Style.TextStyle.Font = New NFont("Arimo", 12, ENFontStyle.Bold)
            m_Scale.Labels.Style.TextStyle.Fill = New NColorFill(NColor.White)
            m_Scale.Labels.Style.Angle = New NScaleLabelAngle(ENScaleLabelAngleMode.Scale, 0)
            m_Scale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None

            ' Value Indicator
            m_NeedleValueIndicator = New NNeedleValueIndicator()
            m_NeedleValueIndicator.Fill = New NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, NColor.White, NColor.Red)
            m_NeedleValueIndicator.Stroke.Color = NColor.Red
            m_NeedleValueIndicator.OffsetFromScale = 2
            m_NeedleValueIndicator.Shape = ENNeedleShape.Triangle
            m_RadialGauge.SweepAngle = New NAngle(360, NUnit.Degree)

            m_RadialGauge.Indicators.Add(m_NeedleValueIndicator)

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

            m_Range = 100

            ' radio buttons
            m_StepAndRotateScaleRadioButton = New NRadioButton("Step and Rotate Scale")
            m_ContinuouslyRotateRadioButton = New NRadioButton("Continuously Rotate")
            m_ContinuouslyRotateRadioButton.Checked = True

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

            Dim dynamicScaleRotationStylesGroup As NRadioButtonGroup = New NRadioButtonGroup(stack)
            dynamicScaleRotationStylesGroup.SelectedIndex = 0

            stack.Add(m_StepAndRotateScaleRadioButton)
            stack.Add(m_ContinuouslyRotateRadioButton)

            Return dynamicScaleRotationStylesGroup
        End Function
        ''' 
        ''' 
        ''' 
        ''' 
        Public Function GetExampleDescription() As String
            Return "

" 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" #End Region #Region "Fields" Private m_RadialGauge As NRadialGauge Private m_NeedleValueIndicator As NNeedleValueIndicator Private m_Scale As NStandardScale Private m_Timer As NTimer Private m_StepAndRotateScaleRadioButton As NRadioButton Private m_ContinuouslyRotateRadioButton As NRadioButton #End Region #Region "Static Methods" #End Region #Region "Constants" Private Shared ReadOnly defaultRadialGaugeSize As NSize = New NSize(300, 300) Private rand As Random = New Random() Private m_CurBegin As Double Private m_CurEnd As Double Private m_InitBegin As Double Private m_InitEnd As Double Private m_Range As Double Private m_FirstIndicatorAngle As Double Const c_ScaleRange As Double = 50 Const c_RotateIncrement As Double = 2 Private m_Increase As Boolean = True Private m_Direction As Integer = 1 Private m_MoveRange As Boolean = False #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Auto Adjusting Scale Example for WinForms Solution