Dragging Indicators Example for WPF

Nevron NOV Gauge for WPF ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WPF 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.

Dragging Indicators Example for WPF Description

The example demonstrates how to enable dragging of gauge indicators.


Dragging Gauge Indicators Example

C# Dragging Indicators Example Code for Nevron Gauge for WPF
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
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.Windows.Forms;

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

		public Form1()
		{
			InitializeComponent();

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

			// 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
			NRadialGauge radialGauge = new NRadialGauge();
			controlStack.Add(radialGauge);

			radialGauge.Dial = new NDial(ENDialShape.Circle, new NEdgeDialRim());
			radialGauge.PreferredSize = defaultRadialGaugeSize;
			radialGauge.Dial.BackgroundFill = new NStockGradientFill(NColor.DarkGray, NColor.Black);
			radialGauge.CapEffect = new NGlassCapEffect();

			// configure the axis
			NGaugeAxis axis = new NGaugeAxis();
			radialGauge.Axes.Add(axis);

			NStandardScale scale = (NStandardScale)axis.Scale;

			scale.SetPredefinedScale(ENPredefinedScaleStyle.Scientific);
			scale.Labels.Style.TextStyle.Fill = new NColorFill(NColor.White);
			scale.Labels.Style.TextStyle.Font = new NFont("Tinos", 10, ENFontStyle.Italic | ENFontStyle.Bold);

			scale.OuterMajorTicks.Stroke.Color = NColor.White;
			scale.OuterMajorTicks.Length = 6;

			scale.OuterMinorTicks.Stroke.Color = NColor.White;
			scale.OuterMinorTicks.Length = 4;

			scale.Ruler.Stroke.Color = NColor.White;
			scale.MinorTickCount = 4;

			// add some indicators
			m_RangeIndicator = new NRangeIndicator();
			m_RangeIndicator.Value = 50;
			m_RangeIndicator.Palette = new NTwoColorPalette(NColor.DarkBlue, NColor.LightBlue);
			m_RangeIndicator.Stroke = null;
			m_RangeIndicator.EndWidth = 20;
			m_RangeIndicator.AllowDragging = true;
			radialGauge.Indicators.Add(m_RangeIndicator);

			m_NeedleIndicator = new NNeedleValueIndicator();
			m_NeedleIndicator.Value = 79;
			m_NeedleIndicator.AllowDragging = true;
			radialGauge.Indicators.Add(m_NeedleIndicator);
			radialGauge.SweepAngle = new NAngle(270, NUnit.Degree);

			m_MarkerIndicator = new NMarkerValueIndicator();
			m_MarkerIndicator.Value = 90;
			m_MarkerIndicator.AllowDragging = true;
			m_MarkerIndicator.OffsetOriginMode = ENIndicatorOffsetOriginMode.ScaleEnd;
			m_MarkerIndicator.OffsetFromScale = 0.0;
			radialGauge.Indicators.Add(m_MarkerIndicator);

			return stack;
		}

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

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

			m_IndicatorSnapModeComboBox = new NComboBox();
			m_IndicatorSnapModeComboBox.Items.Fill(new string[] { "None", "Ruler", "Major ticks", "Minor ticks", "Ruler Min/Max", "Numeric" });
			m_IndicatorSnapModeComboBox.SelectedIndex = 0;
			m_IndicatorSnapModeComboBox.SelectedIndexChanged += OnUdpdateIndicatorValueSnapper;
			propertyStack.Add(new NPairBox("Indicator Snap Mode:", m_IndicatorSnapModeComboBox, true));

			m_StepNumericUpDown = new NNumericUpDown();
			m_StepNumericUpDown.Enabled = false;
			m_StepNumericUpDown.Value = 5.0;
			m_StepNumericUpDown.ValueChanged += OnUdpdateIndicatorValueSnapper;
			propertyStack.Add(new NPairBox("Step:", m_StepNumericUpDown, true));

			m_AllowDraggingRangeIndicator = new NCheckBox("Allow Dragging Range");
			m_AllowDraggingRangeIndicator.Checked = m_RangeIndicator.AllowDragging;
			m_AllowDraggingRangeIndicator.CheckedChanged += OnAllowDraggingRangeIndicator;
			propertyStack.Add(m_AllowDraggingRangeIndicator);

			m_AllowDraggingNeedleIndicator = new NCheckBox("Allow Dragging Needle");
			m_AllowDraggingNeedleIndicator.Checked = m_NeedleIndicator.AllowDragging;
			m_AllowDraggingNeedleIndicator.CheckedChanged += OnAllowDraggingNeedleIndicator;
			propertyStack.Add(m_AllowDraggingNeedleIndicator);

			m_AllowDraggingMarkerIndicator = new NCheckBox("Allow Dragging Marker");
			m_AllowDraggingMarkerIndicator.Checked = m_MarkerIndicator.AllowDragging;
			m_AllowDraggingMarkerIndicator.CheckedChanged += OnAllowDraggingMarkerIndicator;
			propertyStack.Add(m_AllowDraggingMarkerIndicator);

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

The example demonstrates how to enable dragging of gauge indicators.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Gauges Indicators Overview", "https://www.nevron.com/docs/openvision/gauges-indicators-overview.html"), ("Gauges Knob Indicator", "https://www.nevron.com/docs/openvision/gauges-knob-indicator.html"), ("Gauges Needle Indicator", "https://www.nevron.com/docs/openvision/gauges-needle-indicator.html"), }; } #endregion #region Implementation /// /// Creates an indicator value snapper /// /// private NValueSnapper CreateValueSnapper() { switch (m_IndicatorSnapModeComboBox.SelectedIndex) { case 0: //None, snapping is disabled return null; case 1: // Ruler, values are constrained to the ruler begin and end values. return new NAxisRulerClampSnapper(); case 2: // Major ticks, values are snapped to axis major ticks return new NAxisMajorTickSnapper(); case 3: // Minor ticks, values are snapped to axis minor ticks return new NAxisMinorTickSnapper(); case 4: // Ruler Min Max, values are snapped to the ruler min and max values return new NAxisRulerMinMaxSnapper(); case 5: return new NNumericValueSnapper(0.0, m_StepNumericUpDown.Value); default: return null; } } #endregion #region Event Handlers void OnAllowDraggingMarkerIndicator(NValueChangeEventArgs arg) { m_MarkerIndicator.AllowDragging = m_AllowDraggingMarkerIndicator.Checked; } void OnAllowDraggingNeedleIndicator(NValueChangeEventArgs arg) { m_NeedleIndicator.AllowDragging = m_AllowDraggingNeedleIndicator.Checked; } void OnAllowDraggingRangeIndicator(NValueChangeEventArgs arg) { m_RangeIndicator.AllowDragging = m_AllowDraggingRangeIndicator.Checked; } void OnUdpdateIndicatorValueSnapper(NValueChangeEventArgs arg) { m_RangeIndicator.ValueSnapper = CreateValueSnapper(); m_NeedleIndicator.ValueSnapper = CreateValueSnapper(); m_MarkerIndicator.ValueSnapper = CreateValueSnapper(); } void OnAllowDragRangeIndicatorsCheckBoxCheckedChanged(NValueChangeEventArgs arg) { // m_Indicator1.AllowDragging = m_AllowDragRangeIndicatorsCheckBox.Checked; } #endregion #region Fields NRangeIndicator m_RangeIndicator; NNeedleValueIndicator m_NeedleIndicator; NMarkerValueIndicator m_MarkerIndicator; NNumericUpDown m_StepNumericUpDown; NComboBox m_IndicatorSnapModeComboBox; NCheckBox m_AllowDraggingRangeIndicator; NCheckBox m_AllowDraggingNeedleIndicator; NCheckBox m_AllowDraggingMarkerIndicator; #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) Dragging Indicators Example for WPF Solution

VB.NET Dragging Indicators Example Code for Nevron Gauge for WPF
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.Wpf

Class MainWindow

#Region "Constructors"

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

		' Add any initialization after the InitializeComponent() call.

		' Set form title
		Title = "NOV WPF - NDraggingGaugeIndicatorsExample"

		' 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)
		Content = 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
            Dim radialGauge As NRadialGauge = New NRadialGauge()
            controlStack.Add(radialGauge)

            radialGauge.Dial = New NDial(ENDialShape.Circle, New NEdgeDialRim())
            radialGauge.PreferredSize = defaultRadialGaugeSize
            radialGauge.Dial.BackgroundFill = New NStockGradientFill(NColor.DarkGray, NColor.Black)
            radialGauge.CapEffect = New NGlassCapEffect()

            ' configure the axis
            Dim axis As NGaugeAxis = New NGaugeAxis()
            radialGauge.Axes.Add(axis)

            Dim scale = CType(axis.Scale, NStandardScale)

            scale.SetPredefinedScale(ENPredefinedScaleStyle.Scientific)
            scale.Labels.Style.TextStyle.Fill = New NColorFill(NColor.White)
            scale.Labels.Style.TextStyle.Font = New NFont("Tinos", 10, ENFontStyle.Italic Or ENFontStyle.Bold)

            scale.OuterMajorTicks.Stroke.Color = NColor.White
            scale.OuterMajorTicks.Length = 6

            scale.OuterMinorTicks.Stroke.Color = NColor.White
            scale.OuterMinorTicks.Length = 4

            scale.Ruler.Stroke.Color = NColor.White
            scale.MinorTickCount = 4

            ' add some indicators
            m_RangeIndicator = New NRangeIndicator()
            m_RangeIndicator.Value = 50
            m_RangeIndicator.Palette = New NTwoColorPalette(NColor.DarkBlue, NColor.LightBlue)
            m_RangeIndicator.Stroke = Nothing
            m_RangeIndicator.EndWidth = 20
            m_RangeIndicator.AllowDragging = True
            radialGauge.Indicators.Add(m_RangeIndicator)

            m_NeedleIndicator = New NNeedleValueIndicator()
            m_NeedleIndicator.Value = 79
            m_NeedleIndicator.AllowDragging = True
            radialGauge.Indicators.Add(m_NeedleIndicator)
            radialGauge.SweepAngle = New NAngle(270, NUnit.Degree)

            m_MarkerIndicator = New NMarkerValueIndicator()
            m_MarkerIndicator.Value = 90
            m_MarkerIndicator.AllowDragging = True
            m_MarkerIndicator.OffsetOriginMode = ENIndicatorOffsetOriginMode.ScaleEnd
            m_MarkerIndicator.OffsetFromScale = 0.0
            radialGauge.Indicators.Add(m_MarkerIndicator)

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

            m_IndicatorSnapModeComboBox = New NComboBox()
            m_IndicatorSnapModeComboBox.Items.Fill(New String() {"None", "Ruler", "Major ticks", "Minor ticks", "Ruler Min/Max", "Numeric"})
            m_IndicatorSnapModeComboBox.SelectedIndex = 0
            Me.m_IndicatorSnapModeComboBox.SelectedIndexChanged += AddressOf OnUdpdateIndicatorValueSnapper
            propertyStack.Add(New NPairBox("Indicator Snap Mode:", m_IndicatorSnapModeComboBox, True))

            m_StepNumericUpDown = New NNumericUpDown()
            m_StepNumericUpDown.Enabled = False
            m_StepNumericUpDown.Value = 5.0
            Me.m_StepNumericUpDown.ValueChanged += AddressOf OnUdpdateIndicatorValueSnapper
            propertyStack.Add(New NPairBox("Step:", m_StepNumericUpDown, True))

            m_AllowDraggingRangeIndicator = New NCheckBox("Allow Dragging Range")
            m_AllowDraggingRangeIndicator.Checked = m_RangeIndicator.AllowDragging
            Me.m_AllowDraggingRangeIndicator.CheckedChanged += AddressOf OnAllowDraggingRangeIndicator
            propertyStack.Add(m_AllowDraggingRangeIndicator)

            m_AllowDraggingNeedleIndicator = New NCheckBox("Allow Dragging Needle")
            m_AllowDraggingNeedleIndicator.Checked = m_NeedleIndicator.AllowDragging
            Me.m_AllowDraggingNeedleIndicator.CheckedChanged += AddressOf OnAllowDraggingNeedleIndicator
            propertyStack.Add(m_AllowDraggingNeedleIndicator)

            m_AllowDraggingMarkerIndicator = New NCheckBox("Allow Dragging Marker")
            m_AllowDraggingMarkerIndicator.Checked = m_MarkerIndicator.AllowDragging
            Me.m_AllowDraggingMarkerIndicator.CheckedChanged += AddressOf OnAllowDraggingMarkerIndicator
            propertyStack.Add(m_AllowDraggingMarkerIndicator)

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

The example demonstrates how to enable dragging of gauge indicators.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Gauges Indicators Overview", "https://www.nevron.com/docs/openvision/gauges-indicators-overview.html"), ("Gauges Knob Indicator", "https://www.nevron.com/docs/openvision/gauges-knob-indicator.html"), ("Gauges Needle Indicator", "https://www.nevron.com/docs/openvision/gauges-needle-indicator.html")} End Function #End Region #Region "Implementation" ''' ''' Creates an indicator value snapper ''' ''' Private Function CreateValueSnapper() As NValueSnapper Select Case m_IndicatorSnapModeComboBox.SelectedIndex Case 0 'None, snapping is disabled Return Nothing Case 1 ' Ruler, values are constrained to the ruler begin and end values. Return New NAxisRulerClampSnapper() Case 2 ' Major ticks, values are snapped to axis major ticks Return New NAxisMajorTickSnapper() Case 3 ' Minor ticks, values are snapped to axis minor ticks Return New NAxisMinorTickSnapper() Case 4 ' Ruler Min Max, values are snapped to the ruler min and max values Return New NAxisRulerMinMaxSnapper() Case 5 Return New NNumericValueSnapper(0.0, m_StepNumericUpDown.Value) Case Else Return Nothing End Select End Function #End Region #Region "Event Handlers" Private Sub OnAllowDraggingMarkerIndicator(arg As NValueChangeEventArgs) m_MarkerIndicator.AllowDragging = m_AllowDraggingMarkerIndicator.Checked End Sub Private Sub OnAllowDraggingNeedleIndicator(arg As NValueChangeEventArgs) m_NeedleIndicator.AllowDragging = m_AllowDraggingNeedleIndicator.Checked End Sub Private Sub OnAllowDraggingRangeIndicator(arg As NValueChangeEventArgs) m_RangeIndicator.AllowDragging = m_AllowDraggingRangeIndicator.Checked End Sub Private Sub OnUdpdateIndicatorValueSnapper(arg As NValueChangeEventArgs) m_RangeIndicator.ValueSnapper = CreateValueSnapper() m_NeedleIndicator.ValueSnapper = CreateValueSnapper() m_MarkerIndicator.ValueSnapper = CreateValueSnapper() End Sub Private Sub OnAllowDragRangeIndicatorsCheckBoxCheckedChanged(arg As NValueChangeEventArgs) ' m_Indicator1.AllowDragging = m_AllowDragRangeIndicatorsCheckBox.Checked; End Sub #End Region #Region "Fields" Private m_RangeIndicator As NRangeIndicator Private m_NeedleIndicator As NNeedleValueIndicator Private m_MarkerIndicator As NMarkerValueIndicator Private m_StepNumericUpDown As NNumericUpDown Private m_IndicatorSnapModeComboBox As NComboBox Private m_AllowDraggingRangeIndicator As NCheckBox Private m_AllowDraggingNeedleIndicator As NCheckBox Private m_AllowDraggingMarkerIndicator 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) Dragging Indicators Example for WPF Solution