Minimum, Maximum and Interval Example for WinForms

Minimum, Maximum and Interval 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.

Minimum, Maximum and Interval Example for WinForms Description

This sample demonstrates how to set a scale's minimum, maximum, and interval values.Scale range is specified using minimum and maximum values, and the Minimum value can't be equal to or more than the maximum. The scale interval defines the distance between the major tick marks and the labels.


Scales Min Max Example

C# Minimum, Maximum and Interval 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 - NScalesMinMaxExample";

			// 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();
            stack.HorizontalPlacement = ENHorizontalPlacement.Left;

            NStackPanel controlStack = new NStackPanel();
            stack.Add(controlStack);

            // create the radial gauge
            m_RadialGauge = new NRadialGauge();

            m_RadialGauge.PreferredSize = defaultRadialGaugeSize;
            m_RadialGauge.CapEffect = new NGlassCapEffect();
            m_RadialGauge.Dial = new NDial(ENDialShape.Circle, new NEdgeDialRim());

            NAdvancedGradientFill advancedGradient = new NAdvancedGradientFill();
            advancedGradient.BackgroundColor = NColor.BlueViolet;
            advancedGradient.Points.Add(new NAdvancedGradientPoint(NColor.MediumPurple, new NAngle(180, NUnit.Degree), 0.2f, 4, 0.7f, ENAdvancedGradientPointShape.Circle));
            m_RadialGauge.Dial.BackgroundFill = advancedGradient;
            m_RadialGauge.CapEffect = new NGlassCapEffect(ENCapEffectShape.Ellipse);

            m_RadialGauge.SweepAngle = new NAngle(280, NUnit.Degree);
            m_RadialGauge.BeginAngle = new NAngle(120, NUnit.Degree);

            // configure scale
            NGaugeAxis axis = new NGaugeAxis();
            m_RadialGauge.Axes.Clear();
            m_RadialGauge.Axes.Add(axis);

            m_Scale = (NNumericScale)axis.Scale;
            m_Scale.SetPredefinedScale(ENPredefinedScaleStyle.Presentation);

            m_Scale.Ruler.Fill = new NColorFill(NColor.FromColor(NColor.Transparent, 0.4f));
            m_Scale.OuterMajorTicks.Fill = new NColorFill(NColor.White);
            m_Scale.Labels.Style.TextStyle.Font = new NFont("Arial", 12, ENFontStyle.Bold);
            m_Scale.Labels.Style.TextStyle.Fill = new NColorFill(NColor.White);
            m_Scale.MajorTickMode = ENMajorTickMode.CustomStep;
            m_Scale.CustomStep = 10;
            m_Scale.MinorTickCount = 4;
            m_Scale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None;
            //TODO: interval offset 

            // needle value indicator
            m_ValueIndicator = new NNeedleValueIndicator();
            m_ValueIndicator.Value = 79;
            m_ValueIndicator.Fill = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, NColor.White, NColor.Red);
            m_ValueIndicator.Stroke.Color = NColor.White;
            m_ValueIndicator.EnableDampening = true;
            m_ValueIndicator.OffsetFromCenter = -10;
            m_RadialGauge.Indicators.Add(m_ValueIndicator);

            // adds radial gauge
            controlStack.Add(m_RadialGauge);

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

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

            // Range minimum 
            m_RangeMinimumUpDown = new NNumericUpDown();
            m_RangeMinimumUpDown.ValueChanged += OnUpDownRangeMinimumChanged;
            m_RangeMinimumUpDown.Value = 0;
            propertyStack.Add(new NPairBox("Range Minimum:", m_RangeMinimumUpDown, true));

            // Range max 
            m_RangeMaximumUpDown = new NNumericUpDown();
            m_RangeMaximumUpDown.ValueChanged += OnUpDownRangeMaximumChanged;
            m_RangeMaximumUpDown.Value = 120;
            propertyStack.Add(new NPairBox("Range Maximum:", m_RangeMaximumUpDown, true));

            // reversed scale check box
            m_CustomInterval = new NCheckBox("Custom Interval");
            m_CustomInterval.Checked = true;
            m_CustomInterval.CheckedChanged += OnCustomIntervalCheckBoxValueChanged;
            propertyStack.Add(m_CustomInterval);

            // Interval - scale custom step
            m_IntervalUpDown = new NNumericUpDown();
            m_IntervalUpDown.Value = m_Scale.CustomStep;
            m_IntervalUpDown.ValueChanged += OnUpDownIntervalChanged;
            m_IntervalUpDown.Value = Math.Min(Math.Max(m_IntervalUpDown.Value, 10), 50);
            propertyStack.Add(new NPairBox("Interval: ", m_IntervalUpDown, true));



            return stack;
        }
        public string GetExampleDescription()
        {
            return @"

This sample demonstrates how to set a scale's minimum, maximum, and interval values.Scale range is specified using minimum and maximum values, and the Minimum value can't be equal to or more than the maximum. The scale interval defines the distance between the major tick marks and the labels.

"; } /// /// 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 OnUpDownRangeMinimumChanged(NValueChangeEventArgs arg) { int newMinimum = (int)m_RangeMinimumUpDown.Value; if (newMinimum > 100) { newMinimum = 100; } else if(newMinimum <= 0) { newMinimum = 0; } UpdateAxisRange(newMinimum, (int)m_RadialGauge.Axes[0].Range.End); } /// /// /// /// private void OnUpDownRangeMaximumChanged(NValueChangeEventArgs arg) { int newMaximum = (int)m_RangeMaximumUpDown.Value; if (newMaximum > 300) { newMaximum = 300; } else if (newMaximum <= 120) { newMaximum = 120; } ChangeFontSize(newMaximum); UpdateAxisRange((int)m_RadialGauge.Axes[0].Range.Begin, newMaximum); } /// /// /// /// /// private void OnCustomIntervalCheckBoxValueChanged(NValueChangeEventArgs arg) { NCheckBox checkbox = (NCheckBox)arg.TargetNode; if (!checkbox.Checked) m_Scale.CustomStep = 10; m_IntervalUpDown.Enabled = checkbox.Checked; } /// /// Get the new interval value. The value should be between 10 and 50 /// /// private void OnUpDownIntervalChanged(NValueChangeEventArgs arg) { int newInterval = (int)m_IntervalUpDown.Value; if (newInterval > 50 || newInterval <= 10) return; m_Scale.CustomStep = newInterval; } /// /// Updates axis range of the radial gauge /// /// The new minimum value for the axis range /// The new maximum value for the axis range private void UpdateAxisRange(int newMinimum, int newMaximum) { // Check if the new minimum is greater than or equal to the new maximum if (newMinimum >= newMaximum) return; m_RadialGauge.Axes[0].Range = new NRange(newMinimum, newMaximum); } /// /// Changes the font size of the scale labels based on the new maximum value /// /// private void ChangeFontSize(int newMaximum) { if (newMaximum < 150) { m_Scale.Labels.Style.TextStyle.Font = new NFont("Arial", 12, ENFontStyle.Bold); } else if (newMaximum >= 150 && newMaximum <= 200) { m_Scale.Labels.Style.TextStyle.Font = new NFont("Arial", 8, ENFontStyle.Bold); } else if (newMaximum >= 201 && newMaximum <= 300) { m_Scale.Labels.Style.TextStyle.Font = new NFont("Arial", 6, ENFontStyle.Bold); } } #endregion #region Fields NRadialGauge m_RadialGauge; NNeedleValueIndicator m_ValueIndicator; NNumericScale m_Scale; NNumericUpDown m_RangeMinimumUpDown; NNumericUpDown m_RangeMaximumUpDown; NNumericUpDown m_IntervalUpDown; NCheckBox m_CustomInterval; #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) Minimum, Maximum and Interval Example for WinForms Solution

VB.NET Minimum, Maximum and Interval 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 - NScalesMinMaxExample"

        ' 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()
            stack.HorizontalPlacement = ENHorizontalPlacement.Left

            Dim controlStack As NStackPanel = New NStackPanel()
            stack.Add(controlStack)

            ' create the radial gauge
            m_RadialGauge = New NRadialGauge()

            m_RadialGauge.PreferredSize = defaultRadialGaugeSize
            m_RadialGauge.CapEffect = New NGlassCapEffect()
            m_RadialGauge.Dial = New NDial(ENDialShape.Circle, New NEdgeDialRim())

            Dim advancedGradient As NAdvancedGradientFill = New NAdvancedGradientFill()
            advancedGradient.BackgroundColor = NColor.BlueViolet
            advancedGradient.Points.Add(New NAdvancedGradientPoint(NColor.MediumPurple, New NAngle(180, NUnit.Degree), 0.2F, 4, 0.7F, ENAdvancedGradientPointShape.Circle))
            m_RadialGauge.Dial.BackgroundFill = advancedGradient
            m_RadialGauge.CapEffect = New NGlassCapEffect(ENCapEffectShape.Ellipse)

            m_RadialGauge.SweepAngle = New NAngle(280, NUnit.Degree)
            m_RadialGauge.BeginAngle = New NAngle(120, NUnit.Degree)

            ' configure scale
            Dim axis As NGaugeAxis = New NGaugeAxis()
            m_RadialGauge.Axes.Clear()
            m_RadialGauge.Axes.Add(axis)

            m_Scale = CType(axis.Scale, NNumericScale)
            m_Scale.SetPredefinedScale(ENPredefinedScaleStyle.Presentation)

            m_Scale.Ruler.Fill = New NColorFill(NColor.FromColor(NColor.Transparent, 0.4F))
            m_Scale.OuterMajorTicks.Fill = New NColorFill(NColor.White)
            m_Scale.Labels.Style.TextStyle.Font = New NFont("Arial", 12, ENFontStyle.Bold)
            m_Scale.Labels.Style.TextStyle.Fill = New NColorFill(NColor.White)
            m_Scale.MajorTickMode = ENMajorTickMode.CustomStep
            m_Scale.CustomStep = 10
            m_Scale.MinorTickCount = 4
            m_Scale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None
            'TODO: interval offset 

            ' needle value indicator
            m_ValueIndicator = New NNeedleValueIndicator()
            m_ValueIndicator.Value = 79
            m_ValueIndicator.Fill = New NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, NColor.White, NColor.Red)
            m_ValueIndicator.Stroke.Color = NColor.White
            m_ValueIndicator.EnableDampening = True
            m_ValueIndicator.OffsetFromCenter = -10
            m_RadialGauge.Indicators.Add(m_ValueIndicator)

            ' adds radial gauge
            controlStack.Add(m_RadialGauge)

            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))

            ' Range minimum 
            m_RangeMinimumUpDown = New NNumericUpDown()
            Me.m_RangeMinimumUpDown.ValueChanged += AddressOf OnUpDownRangeMinimumChanged
            m_RangeMinimumUpDown.Value = 0
            propertyStack.Add(New NPairBox("Range Minimum:", m_RangeMinimumUpDown, True))

            ' Range max 
            m_RangeMaximumUpDown = New NNumericUpDown()
            Me.m_RangeMaximumUpDown.ValueChanged += AddressOf OnUpDownRangeMaximumChanged
            m_RangeMaximumUpDown.Value = 120
            propertyStack.Add(New NPairBox("Range Maximum:", m_RangeMaximumUpDown, True))

            ' reversed scale check box
            m_CustomInterval = New NCheckBox("Custom Interval")
            m_CustomInterval.Checked = True
            Me.m_CustomInterval.CheckedChanged += AddressOf OnCustomIntervalCheckBoxValueChanged
            propertyStack.Add(m_CustomInterval)

            ' Interval - scale custom step
            m_IntervalUpDown = New NNumericUpDown()
            m_IntervalUpDown.Value = m_Scale.CustomStep
            Me.m_IntervalUpDown.ValueChanged += AddressOf OnUpDownIntervalChanged
            m_IntervalUpDown.Value = Math.Min(Math.Max(m_IntervalUpDown.Value, 10), 50)
            propertyStack.Add(New NPairBox("Interval: ", m_IntervalUpDown, True))



            Return stack
        End Function
        Public Function GetExampleDescription() As String
            Return "

This sample demonstrates how to set a scale's minimum, maximum, and interval values.Scale range is specified using minimum and maximum values, and the Minimum value can't be equal to or more than the maximum. The scale interval defines the distance between the major tick marks and the labels.

" 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 OnUpDownRangeMinimumChanged(arg As NValueChangeEventArgs) Dim newMinimum As Integer = m_RangeMinimumUpDown.Value If newMinimum > 100 Then newMinimum = 100 ElseIf newMinimum <= 0 Then newMinimum = 0 End If Me.UpdateAxisRange(newMinimum, CInt(m_RadialGauge.Axes(CInt(0)).Range.End)) End Sub ''' ''' ''' ''' Private Sub OnUpDownRangeMaximumChanged(arg As NValueChangeEventArgs) Dim newMaximum As Integer = m_RangeMaximumUpDown.Value If newMaximum > 300 Then newMaximum = 300 ElseIf newMaximum <= 120 Then newMaximum = 120 End If ChangeFontSize(newMaximum) Me.UpdateAxisRange(CInt(m_RadialGauge.Axes(CInt(0)).Range.Begin), newMaximum) End Sub ''' ''' ''' ''' ''' Private Sub OnCustomIntervalCheckBoxValueChanged(arg As NValueChangeEventArgs) Dim checkbox = CType(arg.TargetNode, NCheckBox) If Not checkbox.Checked Then m_Scale.CustomStep = 10 m_IntervalUpDown.Enabled = checkbox.Checked End Sub ''' ''' Get the new interval value. The value should be between 10 and 50 ''' ''' Private Sub OnUpDownIntervalChanged(arg As NValueChangeEventArgs) Dim newInterval As Integer = m_IntervalUpDown.Value If newInterval > 50 OrElse newInterval <= 10 Then Return m_Scale.CustomStep = newInterval End Sub ''' ''' Updates axis range of the radial gauge ''' ''' The new minimum value for the axis range ''' The new maximum value for the axis range Private Sub UpdateAxisRange(newMinimum As Integer, newMaximum As Integer) ' Check if the new minimum is greater than or equal to the new maximum If newMinimum >= newMaximum Then Return m_RadialGauge.Axes(0).Range = New NRange(newMinimum, newMaximum) End Sub ''' ''' Changes the font size of the scale labels based on the new maximum value ''' ''' Private Sub ChangeFontSize(newMaximum As Integer) If newMaximum < 150 Then m_Scale.Labels.Style.TextStyle.Font = New NFont("Arial", 12, ENFontStyle.Bold) ElseIf newMaximum >= 150 AndAlso newMaximum <= 200 Then m_Scale.Labels.Style.TextStyle.Font = New NFont("Arial", 8, ENFontStyle.Bold) ElseIf newMaximum >= 201 AndAlso newMaximum <= 300 Then m_Scale.Labels.Style.TextStyle.Font = New NFont("Arial", 6, ENFontStyle.Bold) End If End Sub #End Region #Region "Fields" Private m_RadialGauge As NRadialGauge Private m_ValueIndicator As NNeedleValueIndicator Private m_Scale As NNumericScale Private m_RangeMinimumUpDown As NNumericUpDown Private m_RangeMaximumUpDown As NNumericUpDown Private m_IntervalUpDown As NNumericUpDown Private m_CustomInterval As NCheckBox #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) Minimum, Maximum and Interval Example for WinForms Solution