Labels Orientation Example for WPF

Labels Orientation 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.

Labels Orientation Example for WPF Description

The example demonstrates how to control the Gauge scale labels orientation.


Gauge Scale Labels Orientation Example

C# Labels Orientation 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 - NGaugeScaleLabelsOrientationExample";

			// 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();
			controlStack.Direction = ENHVDirection.LeftToRight;
			stack.Add(controlStack);

			m_LinearGauge = new NLinearGauge();
			m_LinearGauge.Orientation = ENLinearGaugeOrientation.Vertical;
			m_LinearGauge.PreferredSize = defaultLinearVerticalGaugeSize;
			m_LinearGauge.CapEffect = new NGelCapEffect();
			m_LinearGauge.Border = CreateBorder();
			m_LinearGauge.Padding = new NMargins(20);
			m_LinearGauge.BorderThickness = new NMargins(6);

			controlStack.Add(m_LinearGauge);

			// create the background panel
			NAdvancedGradientFill advGradient = new NAdvancedGradientFill();
			advGradient.BackgroundColor = NColor.Black;
			advGradient.Points.Add(new NAdvancedGradientPoint(NColor.LightGray, new NAngle(10, NUnit.Degree), 0.1f, 0, 1.0f, ENAdvancedGradientPointShape.Circle));
			m_LinearGauge.BackgroundFill = advGradient;
			//          FIX m_LinearGauge.BorderStyle = new NEdgeBorderStyle(BorderShape.RoundedRect);

			NGaugeAxis axis = new NGaugeAxis();
			m_LinearGauge.Axes.Add(axis);
			axis.Anchor = new NModelGaugeAxisAnchor(10, ENVerticalAlignment.Center, ENScaleOrientation.Left);
			ConfigureScale((NLinearScale)axis.Scale);

			// add some indicators
			AddRangeIndicatorToGauge(m_LinearGauge);
			m_LinearGauge.Indicators.Add(new NMarkerValueIndicator(60));

			// create the radial gauge
			m_RadialGauge = new NRadialGauge();
			m_RadialGauge.CapEffect = new NGlassCapEffect();
			m_RadialGauge.Dial = new NDial(ENDialShape.Circle, new NEdgeDialRim());
			controlStack.Add(m_RadialGauge);

			// create the radial gauge
			m_RadialGauge.SweepAngle = new NAngle(270, NUnit.Degree);
			m_RadialGauge.BeginAngle = new NAngle(-90, NUnit.Degree);

			// set some background
			advGradient = new NAdvancedGradientFill();
			advGradient.BackgroundColor = NColor.Black;
			advGradient.Points.Add(new NAdvancedGradientPoint(NColor.White, new NAngle(10, NUnit.Degree), 0.1f, 0, 1.0f, ENAdvancedGradientPointShape.Circle));
			m_RadialGauge.Dial = new NDial(ENDialShape.Circle, new NEdgeDialRim());
			m_RadialGauge.Dial.BackgroundFill = advGradient;

			// configure the axis
			axis = new NGaugeAxis();
			m_RadialGauge.Axes.Add(axis);
			axis.Range = new NRange(0, 100);
			axis.Anchor.ScaleOrientation = ENScaleOrientation.Right;
			axis.Anchor = new NDockGaugeAxisAnchor(ENGaugeAxisDockZone.Top, true, ENScaleOrientation.Right, 0.0f, 100.0f);

			ConfigureScale((NLinearScale)axis.Scale);

			// add some indicators
			AddRangeIndicatorToGauge(m_RadialGauge);

			NNeedleValueIndicator needle = new NNeedleValueIndicator(60);
			needle.OffsetOriginMode = ENIndicatorOffsetOriginMode.ScaleMiddle;
			needle.OffsetFromScale = 15.0;
			m_RadialGauge.Indicators.Add(needle);


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

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

			m_AngleModeComboBox = new NComboBox();
			m_AngleModeComboBox.Items.FillFromEnum();
			m_AngleModeComboBox.SelectedIndexChanged += UpdateScaleLabelAngle;
			propertyStack.Add(new NPairBox("Angle Mode:", m_AngleModeComboBox, true));

			m_CustomAngleNumericUpDown = new NNumericUpDown();
			m_CustomAngleNumericUpDown.Minimum = -360;
			m_CustomAngleNumericUpDown.Maximum = 360;
			m_CustomAngleNumericUpDown.ValueChanged += UpdateScaleLabelAngle;
			propertyStack.Add(new NPairBox("Custom Angle:", m_CustomAngleNumericUpDown, true));

			m_AllowTextFlipCheckBox = new NCheckBox("Allow Text to Flip");
			m_AllowTextFlipCheckBox.CheckedChanged += UpdateScaleLabelAngle;
			propertyStack.Add(m_AllowTextFlipCheckBox);

			m_BeginAngleScrollBar = new NHScrollBar();
			m_BeginAngleScrollBar.Minimum = -360;
			m_BeginAngleScrollBar.Maximum = 360;
			m_BeginAngleScrollBar.Value = m_RadialGauge.BeginAngle.ToDegrees();
			m_BeginAngleScrollBar.ValueChanged += OnBeginAngleScrollBarValueChanged;
			propertyStack.Add(new NPairBox("Begin Angle:", m_BeginAngleScrollBar, true));

			m_SweepAngleScrollBar = new NHScrollBar();
			m_SweepAngleScrollBar.Minimum = -360.0;
			m_SweepAngleScrollBar.Maximum = 360.0;
			m_SweepAngleScrollBar.Value = m_RadialGauge.SweepAngle.ToDegrees();
			m_SweepAngleScrollBar.ValueChanged += OnSweepAngleScrollBarValueChanged;
			propertyStack.Add(new NPairBox("Sweep Angle:", m_SweepAngleScrollBar, true));

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

The example demonstrates how to control the Gauge scale labels orientation.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Scale Labels Layout", "https://www.nevron.com/docs/openvision/scale-labels-layout.html"), ("Gauges Axes", "https://www.nevron.com/docs/openvision/gauges-axes.html"), }; } #endregion #region Implementation /// /// /// /// private void ConfigureScale(NLinearScale scale) { scale.SetPredefinedScale(ENPredefinedScaleStyle.PresentationNoStroke); scale.Labels.OverlapResolveLayouts = new NDomArray(); scale.MinorTickCount = 3; scale.Ruler.Fill = new NColorFill(NColor.FromColor(NColor.White, 0.4f)); scale.OuterMajorTicks.Fill = new NColorFill(NColor.Orange); scale.Labels.Style.TextStyle.Font = new NFont("Arimo", 12, ENFontStyle.Bold); scale.Labels.Style.TextStyle.Fill = new NColorFill(NColor.White); } /// /// /// /// private void AddRangeIndicatorToGauge(NGauge gauge) { // add some indicators NRangeIndicator rangeIndicator = new NRangeIndicator(new NRange(75, 100)); rangeIndicator.Fill = new NColorFill(NColor.Red); rangeIndicator.Stroke.Width = 0.0; rangeIndicator.BeginWidth = 5.0; rangeIndicator.EndWidth = 10.0; rangeIndicator.PaintOrder = ENIndicatorPaintOrder.BeforeScale; gauge.Indicators.Add(rangeIndicator); } #endregion #region Event Handlers private void UpdateScaleLabelAngle(NValueChangeEventArgs arg) { NScaleLabelAngle angle = new NScaleLabelAngle((ENScaleLabelAngleMode)m_AngleModeComboBox.SelectedIndex, (float)m_CustomAngleNumericUpDown.Value, m_AllowTextFlipCheckBox.Checked); // apply angle to radial gauge axis NGaugeAxis axis = (NGaugeAxis)m_RadialGauge.Axes[0]; NLinearScale scale = (NLinearScale)axis.Scale; scale.Labels.Style.Angle = angle; // apply angle to linear gauge axis axis = (NGaugeAxis)m_LinearGauge.Axes[0]; scale = (NLinearScale)axis.Scale; scale.Labels.Style.Angle = angle; } void OnBeginAngleScrollBarValueChanged(NValueChangeEventArgs arg) { m_RadialGauge.BeginAngle = new NAngle(m_BeginAngleScrollBar.Value, NUnit.Degree); } void OnSweepAngleScrollBarValueChanged(NValueChangeEventArgs arg) { m_RadialGauge.SweepAngle = new NAngle(m_SweepAngleScrollBar.Value, NUnit.Degree); } void OnAngleModeComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { m_RadialGauge.SweepAngle = new NAngle(m_SweepAngleScrollBar.Value, NUnit.Degree); } #endregion #region Fields NRadialGauge m_RadialGauge; NLinearGauge m_LinearGauge; NComboBox m_AngleModeComboBox; NNumericUpDown m_CustomAngleNumericUpDown; NCheckBox m_AllowTextFlipCheckBox; NHScrollBar m_BeginAngleScrollBar; NHScrollBar m_SweepAngleScrollBar; #endregion #region Static Methods private static NBorder CreateBorder() { return NBorder.CreateThreeColorBorder(NColor.LightGray, NColor.White, NColor.DarkGray, 10, 10); } #endregion #region Constants private static readonly NSize defaultLinearVerticalGaugeSize = new NSize(100, 300); #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Labels Orientation Example for WPF Solution

VB.NET Labels Orientation 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 - NGaugeScaleLabelsOrientationExample"

		' 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()
            controlStack.Direction = ENHVDirection.LeftToRight
            stack.Add(controlStack)

            m_LinearGauge = New NLinearGauge()
            m_LinearGauge.Orientation = ENLinearGaugeOrientation.Vertical
            m_LinearGauge.PreferredSize = defaultLinearVerticalGaugeSize
            m_LinearGauge.CapEffect = New NGelCapEffect()
            m_LinearGauge.Border = CreateBorder()
            m_LinearGauge.Padding = New NMargins(20)
            m_LinearGauge.BorderThickness = New NMargins(6)

            controlStack.Add(m_LinearGauge)

            ' create the background panel
            Dim advGradient As NAdvancedGradientFill = New NAdvancedGradientFill()
            advGradient.BackgroundColor = NColor.Black
            advGradient.Points.Add(New NAdvancedGradientPoint(NColor.LightGray, New NAngle(10, NUnit.Degree), 0.1F, 0, 1.0F, ENAdvancedGradientPointShape.Circle))
            m_LinearGauge.BackgroundFill = advGradient
            '          FIX m_LinearGauge.BorderStyle = new NEdgeBorderStyle(BorderShape.RoundedRect);

            Dim axis As NGaugeAxis = New NGaugeAxis()
            m_LinearGauge.Axes.Add(axis)
            axis.Anchor = New NModelGaugeAxisAnchor(10, ENVerticalAlignment.Center, ENScaleOrientation.Left)
            ConfigureScale(CType(axis.Scale, NLinearScale))

            ' add some indicators
            AddRangeIndicatorToGauge(m_LinearGauge)
            m_LinearGauge.Indicators.Add(New NMarkerValueIndicator(60))

            ' create the radial gauge
            m_RadialGauge = New NRadialGauge()
            m_RadialGauge.CapEffect = New NGlassCapEffect()
            m_RadialGauge.Dial = New NDial(ENDialShape.Circle, New NEdgeDialRim())
            controlStack.Add(m_RadialGauge)

            ' create the radial gauge
            m_RadialGauge.SweepAngle = New NAngle(270, NUnit.Degree)
            m_RadialGauge.BeginAngle = New NAngle(-90, NUnit.Degree)

            ' set some background
            advGradient = New NAdvancedGradientFill()
            advGradient.BackgroundColor = NColor.Black
            advGradient.Points.Add(New NAdvancedGradientPoint(NColor.White, New NAngle(10, NUnit.Degree), 0.1F, 0, 1.0F, ENAdvancedGradientPointShape.Circle))
            m_RadialGauge.Dial = New NDial(ENDialShape.Circle, New NEdgeDialRim())
            m_RadialGauge.Dial.BackgroundFill = advGradient

            ' configure the axis
            axis = New NGaugeAxis()
            m_RadialGauge.Axes.Add(axis)
            axis.Range = New NRange(0, 100)
            axis.Anchor.ScaleOrientation = ENScaleOrientation.Right
            axis.Anchor = New NDockGaugeAxisAnchor(ENGaugeAxisDockZone.Top, True, ENScaleOrientation.Right, 0.0F, 100.0F)

            ConfigureScale(CType(axis.Scale, NLinearScale))

            ' add some indicators
            AddRangeIndicatorToGauge(m_RadialGauge)

            Dim needle As NNeedleValueIndicator = New NNeedleValueIndicator(60)
            needle.OffsetOriginMode = ENIndicatorOffsetOriginMode.ScaleMiddle
            needle.OffsetFromScale = 15.0
            m_RadialGauge.Indicators.Add(needle)


            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_AngleModeComboBox = New NComboBox()
            m_AngleModeComboBox.Items.FillFromEnum(Of ENScaleLabelAngleMode)()
            Me.m_AngleModeComboBox.SelectedIndexChanged += AddressOf UpdateScaleLabelAngle
            propertyStack.Add(New NPairBox("Angle Mode:", m_AngleModeComboBox, True))

            m_CustomAngleNumericUpDown = New NNumericUpDown()
            m_CustomAngleNumericUpDown.Minimum = -360
            m_CustomAngleNumericUpDown.Maximum = 360
            Me.m_CustomAngleNumericUpDown.ValueChanged += AddressOf UpdateScaleLabelAngle
            propertyStack.Add(New NPairBox("Custom Angle:", m_CustomAngleNumericUpDown, True))

            m_AllowTextFlipCheckBox = New NCheckBox("Allow Text to Flip")
            Me.m_AllowTextFlipCheckBox.CheckedChanged += AddressOf UpdateScaleLabelAngle
            propertyStack.Add(m_AllowTextFlipCheckBox)

            m_BeginAngleScrollBar = New NHScrollBar()
            m_BeginAngleScrollBar.Minimum = -360
            m_BeginAngleScrollBar.Maximum = 360
            m_BeginAngleScrollBar.Value = m_RadialGauge.BeginAngle.ToDegrees()
            Me.m_BeginAngleScrollBar.ValueChanged += AddressOf OnBeginAngleScrollBarValueChanged
            propertyStack.Add(New NPairBox("Begin Angle:", m_BeginAngleScrollBar, True))

            m_SweepAngleScrollBar = New NHScrollBar()
            m_SweepAngleScrollBar.Minimum = -360.0
            m_SweepAngleScrollBar.Maximum = 360.0
            m_SweepAngleScrollBar.Value = m_RadialGauge.SweepAngle.ToDegrees()
            Me.m_SweepAngleScrollBar.ValueChanged += AddressOf OnSweepAngleScrollBarValueChanged
            propertyStack.Add(New NPairBox("Sweep Angle:", m_SweepAngleScrollBar, True))

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

The example demonstrates how to control the Gauge scale labels orientation.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Scale Labels Layout", "https://www.nevron.com/docs/openvision/scale-labels-layout.html"), ("Gauges Axes", "https://www.nevron.com/docs/openvision/gauges-axes.html")} End Function #End Region #Region "Implementation" ''' ''' ''' ''' Private Sub ConfigureScale(scale As NLinearScale) scale.SetPredefinedScale(ENPredefinedScaleStyle.PresentationNoStroke) scale.Labels.OverlapResolveLayouts = New NDomArray(Of ENLevelLabelsLayout)() scale.MinorTickCount = 3 scale.Ruler.Fill = New NColorFill(NColor.FromColor(NColor.White, 0.4F)) scale.OuterMajorTicks.Fill = New NColorFill(NColor.Orange) scale.Labels.Style.TextStyle.Font = New NFont("Arimo", 12, ENFontStyle.Bold) scale.Labels.Style.TextStyle.Fill = New NColorFill(NColor.White) End Sub ''' ''' ''' ''' Private Sub AddRangeIndicatorToGauge(gauge As NGauge) ' add some indicators Dim rangeIndicator As NRangeIndicator = New NRangeIndicator(New NRange(75, 100)) rangeIndicator.Fill = New NColorFill(NColor.Red) rangeIndicator.Stroke.Width = 0.0 rangeIndicator.BeginWidth = 5.0 rangeIndicator.EndWidth = 10.0 rangeIndicator.PaintOrder = ENIndicatorPaintOrder.BeforeScale gauge.Indicators.Add(rangeIndicator) End Sub #End Region #Region "Event Handlers" Private Sub UpdateScaleLabelAngle(arg As NValueChangeEventArgs) Dim angle As NScaleLabelAngle = New NScaleLabelAngle(m_AngleModeComboBox.SelectedIndex, m_CustomAngleNumericUpDown.Value, m_AllowTextFlipCheckBox.Checked) ' apply angle to radial gauge axis Dim axis = m_RadialGauge.Axes(0) Dim scale = CType(axis.Scale, NLinearScale) scale.Labels.Style.Angle = angle ' apply angle to linear gauge axis axis = m_LinearGauge.Axes(0) scale = CType(axis.Scale, NLinearScale) scale.Labels.Style.Angle = angle End Sub Private Sub OnBeginAngleScrollBarValueChanged(arg As NValueChangeEventArgs) m_RadialGauge.BeginAngle = New NAngle(m_BeginAngleScrollBar.Value, NUnit.Degree) End Sub Private Sub OnSweepAngleScrollBarValueChanged(arg As NValueChangeEventArgs) m_RadialGauge.SweepAngle = New NAngle(m_SweepAngleScrollBar.Value, NUnit.Degree) End Sub Private Sub OnAngleModeComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs) m_RadialGauge.SweepAngle = New NAngle(m_SweepAngleScrollBar.Value, NUnit.Degree) End Sub #End Region #Region "Fields" Private m_RadialGauge As NRadialGauge Private m_LinearGauge As NLinearGauge Private m_AngleModeComboBox As NComboBox Private m_CustomAngleNumericUpDown As NNumericUpDown Private m_AllowTextFlipCheckBox As NCheckBox Private m_BeginAngleScrollBar As NHScrollBar Private m_SweepAngleScrollBar As NHScrollBar #End Region #Region "Static Methods" Private Shared Function CreateBorder() As NBorder Return NBorder.CreateThreeColorBorder(NColor.LightGray, NColor.White, NColor.DarkGray, 10, 10) End Function #End Region #Region "Constants" Private Shared ReadOnly defaultLinearVerticalGaugeSize As NSize = New NSize(100, 300) #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Labels Orientation Example for WPF Solution

Related Documentation Links