Measure Up Down Example for Blazor

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

Measure Up Down Example for Blazor 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 Blazor
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 Blazor Solution