Dampening the Pointer Example for WPF

Dampening the Pointer 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.

Dampening the Pointer Example for WPF Description

This example demonstrates how to enable the value dampening feature of the gauge indicators. When enabled the value dampening will smooths the transition of indicators when their value changes. Use the controls on the right side to modify various parameters of the dampening effect.


Pointer Dampening Example

C# Dampening the Pointer Example Code for Nevron Gauge for WPF
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Diagram;
using Nevron.Nov.Diagram.UI;
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.Threading;
using System.Timers;
using System.Windows.Forms;

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

		public Form1()
		{
			InitializeComponent();

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

			// 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;
            m_RadialGauge.Dial = new NDial(ENDialShape.RoundedOutline, new NEdgeDialRim());
            m_RadialGauge.Dial.CornerRounding = 23;
            m_RadialGauge.Dial.BackgroundFill = new NStockGradientFill(NColor.Black, NColor.WhiteSmoke);
            
            m_RadialGauge.SweepAngle = new NAngle(60, NUnit.Degree);
            m_RadialGauge.BeginAngle = new NAngle(240, NUnit.Degree);

            controlStack.Add(m_RadialGauge);

            // create the first axis
            NGaugeAxis axis1 = new NGaugeAxis();
            axis1.Anchor = new NDockGaugeAxisAnchor(ENGaugeAxisDockZone.Top, true, 0, 100);

            m_RadialGauge.Axes.Add(axis1);

            // Scale 
            NStandardScale scale1 = (NStandardScale)axis1.Scale;
            scale1.SetPredefinedScale(ENPredefinedScaleStyle.PresentationNoStroke);
            scale1.MinorTickCount = 10;
            scale1.Ruler.Fill = new NColorFill(NColor.FromColor(NColor.DarkGray,5.0f));
            scale1.OuterMajorTicks.Fill = new NColorFill(NColor.OrangeRed);
            scale1.Labels.Style.TextStyle.Font = new NFont("Arial", 12, ENFontStyle.Regular);
            scale1.Labels.Style.TextStyle.Fill = new NColorFill(NColor.White);
            scale1.Labels.Style.Angle = new NScaleLabelAngle(ENScaleLabelAngleMode.Scale, 0);

            // needle value indicator1
            m_NeedleValueIndicator = new NNeedleValueIndicator();
            m_NeedleValueIndicator.Value = 20;
            m_NeedleValueIndicator.Fill = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, NColor.White, NColor.Red);
            m_NeedleValueIndicator.Stroke.Color = NColor.Red;
            m_NeedleValueIndicator.ScaleAxis = axis1;
            m_NeedleValueIndicator.OffsetFromScale = 2;
            m_NeedleValueIndicator.EnableDampening = true;
        
            m_RadialGauge.Indicators.Add(m_NeedleValueIndicator);

            // marker value indicator 
            m_MarkerValueIndicator = new NMarkerValueIndicator();
            m_MarkerValueIndicator.EnableDampening = true;
            m_MarkerValueIndicator.Value = 20;

            // range value indicator 
            m_RangeValueIndicator = new NRangeIndicator();
            m_RangeValueIndicator.EnableDampening = true;
            m_RangeValueIndicator.Value = 20;

            // Timer
            m_Timer = new NTimer();
            m_Timer.Interval = 1000;
            m_Timer.Tick += OnTimerTick;
            m_Timer.Start();
            return stack;
        }
      
        public NWidget CreateExampleControls()
        {
            NStackPanel stack = new NStackPanel();

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

            // pointer properties group
            NGroupBox controlsGroupBox = new NGroupBox("Controls");
            propertyStack.Add(controlsGroupBox);
            NStackPanel controlsGroupBoxContent = new NStackPanel();
            controlsGroupBox.Content = new NUniSizeBoxGroup(controlsGroupBoxContent);

            NButton toggleTimerButton = new NButton("Stop Timer");
            toggleTimerButton.Click += OnToggleTimerButtonClick;
            toggleTimerButton.Tag = 0;
            stack.Add(toggleTimerButton);

            // enable dampening checkbox
            m_EnableDampeningCheckBox = new NCheckBox("Enable Value Dampening");
            m_EnableDampeningCheckBox.CheckedChanged += OnEnableDampeningCheckBoxCheckedChanged;
            m_EnableDampeningCheckBox.Checked = true;
            propertyStack.Add(m_EnableDampeningCheckBox);

            // dampening steps up and down value 
            m_DampeningStepsUpDown = new NNumericUpDown();
            m_DampeningStepsUpDown.Minimum = 1;
            m_DampeningStepsUpDown.Maximum = 100;
            m_DampeningStepsUpDown.ValueChanged += UpdateDampeingStepsUpAndDown;
            m_DampeningStepsUpDown.Value = 20;
            propertyStack.Add(new NPairBox("Steps: ", m_DampeningStepsUpDown, true));

            // dampening interval up and down value 
            m_DampeningIntervalUpDown = new NNumericUpDown();
            m_DampeningIntervalUpDown.Minimum = 1;
            m_DampeningIntervalUpDown.ValueChanged += UpdateDampeingIntervalUpAndDown;
            m_DampeningIntervalUpDown.Value = 50;
            propertyStack.Add(new NPairBox("Interval: ", m_DampeningIntervalUpDown, true));

            // value indicator combo box
            m_ValueIndicatorTypeComboBox = new NComboBox();
            m_ValueIndicatorTypeComboBox.Items.Add(new NComboBoxItem("Needle"));
            m_ValueIndicatorTypeComboBox.Items.Add(new NComboBoxItem("Marker"));
            m_ValueIndicatorTypeComboBox.Items.Add(new NComboBoxItem("Bar"));
            m_ValueIndicatorTypeComboBox.SelectedIndexChanged += OnValueIndicatorComboBoxIndexChanged;
            m_ValueIndicatorTypeComboBox.SelectedIndex = 0;
            controlsGroupBoxContent.Add(new NPairBox("Marker Pointer Scale:", m_ValueIndicatorTypeComboBox, true));

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

This example demonstrates how to enable the value dampening feature of the gauge indicators. When enabled the value dampening will smooths the transition of indicators when their value changes. Use the controls on the right side to modify various parameters of the dampening effect.

"; } /// /// 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 Axes", "https://www.nevron.com/docs/openvision/gauges-axes.html"), }; } #endregion #region Implementation #endregion #region Event Handlers /// /// /// /// private void OnValueIndicatorComboBoxIndexChanged(NValueChangeEventArgs arg) { m_RadialGauge.Indicators.Clear(); switch ((int)arg.NewValue) { case 0: m_RadialGauge.Indicators.Add(m_NeedleValueIndicator); break; case 1: m_RadialGauge.Indicators.Add(m_MarkerValueIndicator); break; case 2: m_RadialGauge.Indicators.Add(m_RangeValueIndicator); break; } } /// /// /// /// private void UpdateDampeingIntervalUpAndDown(NValueChangeEventArgs arg) { SetValueIndicator(NValueIndicator.DampeningIntervalProperty, (int)m_DampeningIntervalUpDown.Value); } /// /// /// /// private void UpdateDampeingStepsUpAndDown(NValueChangeEventArgs arg) { SetValueIndicator(NValueIndicator.DampeningStepsProperty, (int)m_DampeningStepsUpDown.Value); } /// /// Set whether dampening is on or off. /// /// private void OnEnableDampeningCheckBoxCheckedChanged(NValueChangeEventArgs arg) { bool enableDampening = (bool)arg.NewValue; m_NeedleValueIndicator.EnableDampening = enableDampening; m_MarkerValueIndicator.EnableDampening = enableDampening; m_RangeValueIndicator.EnableDampening = enableDampening; } /// /// Handles timer's click as evaluating random value and set it on the indicators. /// private void OnTimerTick() { m_Angle += Math.PI / 180.0; double value = 50 + Math.Sin(m_Angle) * (20 + rand.Next(30)); SetValueIndicator(NValueIndicator.ValueProperty, value); } /// /// Set the value of specified properties of the indicators /// /// /// private void SetValueIndicator(NProperty indicatorProperty, double value) { string stringValue = value.ToString(); m_NeedleValueIndicator.SetFx(indicatorProperty, stringValue); m_MarkerValueIndicator.SetFx(indicatorProperty, stringValue); m_RangeValueIndicator.SetFx(indicatorProperty, stringValue); } /// /// /// /// void OnToggleTimerButtonClick(NEventArgs arg) { NButton button = (NButton)arg.TargetNode; if ((int)button.Tag == 0) { m_Timer.Stop(); button.Content = new NLabel("Start Timer"); button.Tag = 1; } else { m_Timer.Start(); button.Content = new NLabel("Stop Timer"); button.Tag = 0; } } #endregion #region Fields NRadialGauge m_RadialGauge; NNeedleValueIndicator m_NeedleValueIndicator; NMarkerValueIndicator m_MarkerValueIndicator; NRangeIndicator m_RangeValueIndicator; NComboBox m_ValueIndicatorTypeComboBox; NNumericUpDown m_DampeningStepsUpDown; NNumericUpDown m_DampeningIntervalUpDown; NCheckBox m_EnableDampeningCheckBox; NTimer m_Timer; double m_Angle; private Random rand = new Random(); #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) Dampening the Pointer Example for WPF Solution

VB.NET Dampening the Pointer 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
Imports System

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

		' 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
            m_RadialGauge = New NRadialGauge()

            m_RadialGauge.PreferredSize = defaultRadialGaugeSize
            m_RadialGauge.Dial = New NDial(ENDialShape.RoundedOutline, New NEdgeDialRim())
            m_RadialGauge.Dial.CornerRounding = 23
            m_RadialGauge.Dial.BackgroundFill = New NStockGradientFill(NColor.Black, NColor.WhiteSmoke)

            m_RadialGauge.SweepAngle = New NAngle(60, NUnit.Degree)
            m_RadialGauge.BeginAngle = New NAngle(240, NUnit.Degree)

            controlStack.Add(m_RadialGauge)

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

            m_RadialGauge.Axes.Add(axis1)

            ' Scale 
            Dim scale1 = CType(axis1.Scale, NStandardScale)
            scale1.SetPredefinedScale(ENPredefinedScaleStyle.PresentationNoStroke)
            scale1.MinorTickCount = 10
            scale1.Ruler.Fill = New NColorFill(NColor.FromColor(NColor.DarkGray, 5.0F))
            scale1.OuterMajorTicks.Fill = New NColorFill(NColor.OrangeRed)
            scale1.Labels.Style.TextStyle.Font = New NFont("Arial", 12, ENFontStyle.Regular)
            scale1.Labels.Style.TextStyle.Fill = New NColorFill(NColor.White)
            scale1.Labels.Style.Angle = New NScaleLabelAngle(ENScaleLabelAngleMode.Scale, 0)

            ' needle value indicator1
            m_NeedleValueIndicator = New NNeedleValueIndicator()
            m_NeedleValueIndicator.Value = 20
            m_NeedleValueIndicator.Fill = New NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, NColor.White, NColor.Red)
            m_NeedleValueIndicator.Stroke.Color = NColor.Red
            m_NeedleValueIndicator.ScaleAxis = axis1
            m_NeedleValueIndicator.OffsetFromScale = 2
            m_NeedleValueIndicator.EnableDampening = True

            m_RadialGauge.Indicators.Add(m_NeedleValueIndicator)

            ' marker value indicator 
            m_MarkerValueIndicator = New NMarkerValueIndicator()
            m_MarkerValueIndicator.EnableDampening = True
            m_MarkerValueIndicator.Value = 20

            ' range value indicator 
            m_RangeValueIndicator = New NRangeIndicator()
            m_RangeValueIndicator.EnableDampening = True
            m_RangeValueIndicator.Value = 20

            ' Timer
            m_Timer = New NTimer()
            m_Timer.Interval = 1000
            Me.m_Timer.Tick += AddressOf OnTimerTick
            m_Timer.Start()
            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))

            ' pointer properties group
            Dim controlsGroupBox As NGroupBox = New NGroupBox("Controls")
            propertyStack.Add(controlsGroupBox)
            Dim controlsGroupBoxContent As NStackPanel = New NStackPanel()
            controlsGroupBox.Content = New NUniSizeBoxGroup(controlsGroupBoxContent)

            Dim toggleTimerButton As NButton = New NButton("Stop Timer")
            toggleTimerButton.Click += AddressOf OnToggleTimerButtonClick
            toggleTimerButton.Tag = 0
            stack.Add(toggleTimerButton)

            ' enable dampening checkbox
            m_EnableDampeningCheckBox = New NCheckBox("Enable Value Dampening")
            Me.m_EnableDampeningCheckBox.CheckedChanged += AddressOf OnEnableDampeningCheckBoxCheckedChanged
            m_EnableDampeningCheckBox.Checked = True
            propertyStack.Add(m_EnableDampeningCheckBox)

            ' dampening steps up and down value 
            m_DampeningStepsUpDown = New NNumericUpDown()
            m_DampeningStepsUpDown.Minimum = 1
            m_DampeningStepsUpDown.Maximum = 100
            Me.m_DampeningStepsUpDown.ValueChanged += AddressOf UpdateDampeingStepsUpAndDown
            m_DampeningStepsUpDown.Value = 20
            propertyStack.Add(New NPairBox("Steps: ", m_DampeningStepsUpDown, True))

            ' dampening interval up and down value 
            m_DampeningIntervalUpDown = New NNumericUpDown()
            m_DampeningIntervalUpDown.Minimum = 1
            Me.m_DampeningIntervalUpDown.ValueChanged += AddressOf UpdateDampeingIntervalUpAndDown
            m_DampeningIntervalUpDown.Value = 50
            propertyStack.Add(New NPairBox("Interval: ", m_DampeningIntervalUpDown, True))

            ' value indicator combo box
            m_ValueIndicatorTypeComboBox = New NComboBox()
            m_ValueIndicatorTypeComboBox.Items.Add(New NComboBoxItem("Needle"))
            m_ValueIndicatorTypeComboBox.Items.Add(New NComboBoxItem("Marker"))
            m_ValueIndicatorTypeComboBox.Items.Add(New NComboBoxItem("Bar"))
            Me.m_ValueIndicatorTypeComboBox.SelectedIndexChanged += AddressOf OnValueIndicatorComboBoxIndexChanged
            m_ValueIndicatorTypeComboBox.SelectedIndex = 0
            controlsGroupBoxContent.Add(New NPairBox("Marker Pointer Scale:", m_ValueIndicatorTypeComboBox, True))

            Return stack
        End Function

        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to enable the value dampening feature of the gauge indicators. When enabled the value dampening will smooths the transition of indicators when their value changes. Use the controls on the right side to modify various parameters of the dampening effect.

" 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 Axes", "https://www.nevron.com/docs/openvision/gauges-axes.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_MarkerValueIndicator As NMarkerValueIndicator Private m_RangeValueIndicator As NRangeIndicator Private m_ValueIndicatorTypeComboBox As NComboBox Private m_DampeningStepsUpDown As NNumericUpDown Private m_DampeningIntervalUpDown As NNumericUpDown Private m_EnableDampeningCheckBox As NCheckBox Private m_Timer As NTimer Private m_Angle As Double Private rand As Random = New Random() #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) Dampening the Pointer Example for WPF Solution

Related Documentation Links