Measure Up Down Example for WinForms

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

Measure Up Down Example for WinForms Description

This example demonstrates how to create and use measure up downs. The measure up down extends the functionality of the numeric up down by adding a combo box for selecting a unit. If the units can be converted to each other, when the user selects a new unit from the unit combo box, the value will be automatically converted. The Unit property determines the currently selected measurement unit.


Measure up down Example

C# Measure Up Down Example Code for Nevron UserInterface for WinForms
Language: C#

using Nevron.Nov;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
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 - NMeasureUpDownExample";

			// 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()
		{
			m_StackPanel = new NStackPanel();
			m_StackPanel.HorizontalPlacement = ENHorizontalPlacement.Left;
			m_StackPanel.VerticalSpacing = 5;

			m_StackPanel.Add(CreatePairBox(
				"Angle:",
				NUnit.Radian, NUnit.Degree, NUnit.Grad)
			);

			m_StackPanel.Add(CreatePairBox(
				"SI Length:",
				NUnit.Millimeter, NUnit.Centimeter, NUnit.Meter, NUnit.Kilometer)
			);

			m_StackPanel.Add(CreatePairBox(
				"Imperial Length:",
				NUnit.Inch, NUnit.Foot, NUnit.Yard, NUnit.Mile)
			);

			m_StackPanel.Add(CreatePairBox(
				"Mixed Length:",
				NUnit.Millimeter, NUnit.Centimeter, NUnit.Meter, NUnit.Kilometer, NUnit.Inch, NUnit.Foot, NUnit.Yard, NUnit.Mile)
			);

			m_StackPanel.Add(CreatePairBox(
				"Graphics Length:",
				NUnit.Millimeter, NUnit.Inch, NUnit.DIP, NUnit.Point)
			);

			return new NUniSizeBoxGroup(m_StackPanel);
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			stack.FillMode = ENStackFillMode.Last;
			stack.FitMode = ENStackFitMode.Last;

			NCheckBox enabledCheckBox = new NCheckBox("Enabled", true);
			enabledCheckBox.HorizontalPlacement = ENHorizontalPlacement.Left;
			enabledCheckBox.VerticalPlacement = ENVerticalPlacement.Top;
			enabledCheckBox.CheckedChanged += OnEnabledCheckBoxCheckedChanged;
			stack.Add(enabledCheckBox);

			m_EventsLog = new NExampleEventsLog();
			stack.Add(m_EventsLog);

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

This example demonstrates how to create and use measure up downs. The measure up down extends the functionality of the numeric up down by adding a combo box for selecting a unit. If the units can be converted to each other, when the user selects a new unit from the unit combo box, the value will be automatically converted. The Unit property determines the currently selected measurement unit.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Up Down Widgets", "https://www.nevron.com/docs/openvision/ui-up-down-widgets.html"), ("Range Based Widgets Overview", "https://www.nevron.com/docs/openvision/ui-range-based-widgets-overview.html"), }; } #endregion #region Implementation private NPairBox CreatePairBox(string text, params NUnit[] units) { NLabel label = new NLabel(text); label.HorizontalPlacement = ENHorizontalPlacement.Right; label.VerticalPlacement = ENVerticalPlacement.Center; NMeasureUpDown measureUpDown = new NMeasureUpDown(units); measureUpDown.Minimum = Double.MinValue; measureUpDown.Maximum = Double.MaxValue; measureUpDown.Value = 1; measureUpDown.DecimalPlaces = 3; measureUpDown.UnitComboBox.PreferredWidth = 40; measureUpDown.ValueChanged += OnMeasureUpDownValueChanged; NPairBox pairBox = new NPairBox(label, measureUpDown, true); pairBox.Spacing = 3; return pairBox; } #endregion #region Event Handlers private void OnMeasureUpDownValueChanged(NValueChangeEventArgs args) { NMeasureUpDown measureUpDown = (NMeasureUpDown)args.TargetNode; double value = (double)args.NewValue; NUnit unit = measureUpDown.SelectedUnit; string unitString = unit.ToString(); if (value != 1) { // Make the unit string plural if (unit == NUnit.Inch) { unitString = "inches"; } else if (unit == NUnit.Foot) { unitString = "feet"; } else { unitString += "s"; } } // Log the event m_EventsLog.LogEvent("New value: " + value.ToString() + " " + unitString); } private void OnEnabledCheckBoxCheckedChanged(NValueChangeEventArgs args) { m_StackPanel.Enabled = (bool)args.NewValue; } #endregion #region Fields private NStackPanel m_StackPanel; private NExampleEventsLog m_EventsLog; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Measure Up Down Example for WinForms Solution

VB.NET Measure Up Down Example Code for Nevron UserInterface for WinForms
Language: VB.NET

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

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 - NMeasureUpDownExample"

        ' 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
            m_StackPanel = New NStackPanel()
            m_StackPanel.HorizontalPlacement = ENHorizontalPlacement.Left
            m_StackPanel.VerticalSpacing = 5

            m_StackPanel.Add(CreatePairBox("Angle:", NUnit.Radian, NUnit.Degree, NUnit.Grad))

            m_StackPanel.Add(CreatePairBox("SI Length:", NUnit.Millimeter, NUnit.Centimeter, NUnit.Meter, NUnit.Kilometer))

            m_StackPanel.Add(CreatePairBox("Imperial Length:", NUnit.Inch, NUnit.Foot, NUnit.Yard, NUnit.Mile))

            m_StackPanel.Add(CreatePairBox("Mixed Length:", NUnit.Millimeter, NUnit.Centimeter, NUnit.Meter, NUnit.Kilometer, NUnit.Inch, NUnit.Foot, NUnit.Yard, NUnit.Mile))

            m_StackPanel.Add(CreatePairBox("Graphics Length:", NUnit.Millimeter, NUnit.Inch, NUnit.DIP, NUnit.Point))

            Return New NUniSizeBoxGroup(m_StackPanel)
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()
            stack.FillMode = ENStackFillMode.Last
            stack.FitMode = ENStackFitMode.Last

            Dim enabledCheckBox As NCheckBox = New NCheckBox("Enabled", True)
            enabledCheckBox.HorizontalPlacement = ENHorizontalPlacement.Left
            enabledCheckBox.VerticalPlacement = ENVerticalPlacement.Top
            enabledCheckBox.CheckedChanged += AddressOf OnEnabledCheckBoxCheckedChanged
            stack.Add(enabledCheckBox)

            m_EventsLog = New NExampleEventsLog()
            stack.Add(m_EventsLog)

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

This example demonstrates how to create and use measure up downs. The measure up down extends the functionality of the numeric up down by adding a combo box for selecting a unit. If the units can be converted to each other, when the user selects a new unit from the unit combo box, the value will be automatically converted. The Unit property determines the currently selected measurement unit.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Up Down Widgets", "https://www.nevron.com/docs/openvision/ui-up-down-widgets.html"), ("Range Based Widgets Overview", "https://www.nevron.com/docs/openvision/ui-range-based-widgets-overview.html")} End Function #End Region #Region "Implementation" Private Function CreatePairBox(text As String, ParamArray units As NUnit()) As NPairBox Dim label As NLabel = New NLabel(text) label.HorizontalPlacement = ENHorizontalPlacement.Right label.VerticalPlacement = ENVerticalPlacement.Center Dim measureUpDown As NMeasureUpDown = New NMeasureUpDown(units) measureUpDown.Minimum = Double.MinValue measureUpDown.Maximum = Double.MaxValue measureUpDown.Value = 1 measureUpDown.DecimalPlaces = 3 measureUpDown.UnitComboBox.PreferredWidth = 40 measureUpDown.ValueChanged += AddressOf OnMeasureUpDownValueChanged Dim pairBox As NPairBox = New NPairBox(label, measureUpDown, True) pairBox.Spacing = 3 Return pairBox End Function #End Region #Region "Event Handlers" Private Sub OnMeasureUpDownValueChanged(args As NValueChangeEventArgs) Dim measureUpDown = CType(args.TargetNode, NMeasureUpDown) Dim value As Double = args.NewValue Dim unit As NUnit = measureUpDown.SelectedUnit Dim unitString As String = unit.ToString() If value <> 1 Then ' Make the unit string plural If unit Is NUnit.Inch Then unitString = "inches" ElseIf unit Is NUnit.Foot Then unitString = "feet" Else unitString += "s" End If End If ' Log the event m_EventsLog.LogEvent("New value: " & value.ToString() & " " & unitString) End Sub Private Sub OnEnabledCheckBoxCheckedChanged(args As NValueChangeEventArgs) m_StackPanel.Enabled = CBool(args.NewValue) End Sub #End Region #Region "Fields" Private m_StackPanel As NStackPanel Private m_EventsLog As NExampleEventsLog #End Region #Region "Static Methods" #End Region #Region "Constants" #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Measure Up Down Example for WinForms Solution