Custom Symbols 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.

Custom Symbols Example for WinForms Description

Nevron Open Vision provides support for drawing of vector based shapes called symbols. The advantage of such vector based shapes over regular raster images is that they do not blur and look nice at any size. This example demonstrates how to create and use custom symbols. Use the radio buttons on the right to see the symbols at different sizes.


Custom Symbols Example

C# Custom Symbols Example Code for Nevron UserInterface for WinForms
Language: C#

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

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

		public Form1()
		{
			InitializeComponent();

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

			// 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_SymbolsTable = new NTableFlowPanel();
			m_SymbolsTable.BackgroundFill = new NColorFill(NColor.White);
			m_SymbolsTable.HorizontalSpacing = NDesign.HorizontalSpacing * 3;
			m_SymbolsTable.VerticalSpacing = NDesign.VerticalSpacing * 3;
			m_SymbolsTable.Direction = ENHVDirection.LeftToRight;
			m_SymbolsTable.MaxOrdinal = 2;
			m_SymbolsTable.Padding = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing,
				NDesign.HorizontalSpacing * 6, NDesign.VerticalSpacing);

			RecreateSymbols();

			NScrollContent scrollContent = new NScrollContent(m_SymbolsTable);
			scrollContent.HorizontalPlacement = ENHorizontalPlacement.Left;
			return scrollContent;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			
			// Create the color box
			m_ColorBox = new NColorBox();
			m_ColorBox.SelectedColor = DefaultSymbolColor;
			m_ColorBox.SelectedColorChanged += OnColorBoxSelectedColorChanged;
			stack.Add(NPairBox.Create("Color:", m_ColorBox));

			// Create the size radio button group
			NStackPanel radioStack = new NStackPanel();
			double size = MinSymbolSize;
			int selectedIndex = 0;

			for (int i = 0; i < 4; i++)
			{
				if (size == DefaultSymbolSize)
				{
					selectedIndex = i;
				}

				string sizeStr = size.ToString(CultureInfo.InvariantCulture);
				NRadioButton radioButton = new NRadioButton(sizeStr + "x" + sizeStr);
				radioStack.Add(radioButton);
				size *= 2;
			}

			m_RadioGroup = new NRadioButtonGroup(radioStack);
			m_RadioGroup.SelectedIndex = selectedIndex;
			m_RadioGroup.SelectedIndexChanged += OnRadioGroupSelectedIndexChanged;
			NPairBox pairBox = NPairBox.Create("Size:", m_RadioGroup);
			pairBox.Box1.VerticalPlacement = ENVerticalPlacement.Top;
			stack.Add(pairBox);

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

Nevron Open Vision provides support for drawing of vector based shapes called symbols. The advantage of such vector based shapes over regular raster images is that they do not blur and look nice at any size. This example demonstrates how to create and use custom symbols. Use the radio buttons on the right to see the symbols at different sizes.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Symbols", "https://www.nevron.com/docs/openvision/ui-symbols.html"), ("Widget Elements", "https://www.nevron.com/docs/openvision/ui-widget-elements.html"), }; } #endregion #region Implementation private void RecreateSymbols() { NColor color = m_ColorBox != null ? m_ColorBox.SelectedColor : DefaultSymbolColor; double length = m_RadioGroup != null ? MinSymbolSize * Math.Pow(2, m_RadioGroup.SelectedIndex) : DefaultSymbolSize; NSize size = new NSize(length, length); m_SymbolsTable.Clear(); // Create a triangle up symbol NPolygonSymbolShape shape = new NPolygonSymbolShape(new NPoint[]{ new NPoint(0, size.Height), new NPoint(size.Width * 0.5, 0), new NPoint(size.Width, size.Height)}, ENFillRule.EvenOdd); shape.Fill = new NColorFill(color); NSymbol symbol1 = new NSymbol(); symbol1.Add(shape); AddSymbolBox(symbol1, "Triangle Up"); // Create a rectangle with an ellipse NRectangleSymbolShape rectShape = new NRectangleSymbolShape(0, 0, size.Width, size.Height); rectShape.Fill = new NColorFill(color); NEllipseSymbolShape ellipseShape = new NEllipseSymbolShape(size.Width / 4, size.Height / 4, size.Width / 2, size.Height / 2); ellipseShape.Fill = new NColorFill(color.Invert()); NSymbol symbol2 = new NSymbol(); symbol2.Add(rectShape); symbol2.Add(ellipseShape); AddSymbolBox(symbol2, "Rectangle with an ellipse"); } private void AddSymbolBox(NSymbol symbol, string name) { m_SymbolsTable.Add(new NSymbolBox(symbol)); NLabel label = new NLabel(name); label.VerticalPlacement = ENVerticalPlacement.Center; m_SymbolsTable.Add(label); } #endregion #region Event Handlers private void OnColorBoxSelectedColorChanged(NValueChangeEventArgs arg) { RecreateSymbols(); } private void OnRadioGroupSelectedIndexChanged(NValueChangeEventArgs arg) { RecreateSymbols(); } #endregion #region Fields private NTableFlowPanel m_SymbolsTable; private NColorBox m_ColorBox; private NRadioButtonGroup m_RadioGroup; #endregion #region Static Methods #endregion #region Constants private const double MinSymbolSize = 16; private const double DefaultSymbolSize = 32; private static readonly NColor DefaultSymbolColor = NColor.MediumBlue; #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Custom Symbols Example for WinForms Solution

VB.NET Custom Symbols 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
Imports System
Imports System.Globalization

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

        ' 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_SymbolsTable = New NTableFlowPanel()
            m_SymbolsTable.BackgroundFill = New NColorFill(NColor.White)
            m_SymbolsTable.HorizontalSpacing = NDesign.HorizontalSpacing * 3
            m_SymbolsTable.VerticalSpacing = NDesign.VerticalSpacing * 3
            m_SymbolsTable.Direction = ENHVDirection.LeftToRight
            m_SymbolsTable.MaxOrdinal = 2
            m_SymbolsTable.Padding = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing, NDesign.HorizontalSpacing * 6, NDesign.VerticalSpacing)

            RecreateSymbols()

            Dim scrollContent As NScrollContent = New NScrollContent(m_SymbolsTable)
            scrollContent.HorizontalPlacement = ENHorizontalPlacement.Left
            Return scrollContent
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()

            ' Create the color box
            m_ColorBox = New NColorBox()
            m_ColorBox.SelectedColor = DefaultSymbolColor
            Me.m_ColorBox.SelectedColorChanged += AddressOf OnColorBoxSelectedColorChanged
            stack.Add(NPairBox.Create("Color:", m_ColorBox))

            ' Create the size radio button group
            Dim radioStack As NStackPanel = New NStackPanel()
            Dim size = MinSymbolSize
            Dim selectedIndex = 0

            For i = 0 To 3
                If size = DefaultSymbolSize Then
                    selectedIndex = i
                End If

                Dim sizeStr = size.ToString(CultureInfo.InvariantCulture)
                Dim radioButton As NRadioButton = New NRadioButton(sizeStr & "x" & sizeStr)
                radioStack.Add(radioButton)
                size *= 2
            Next

            m_RadioGroup = New NRadioButtonGroup(radioStack)
            m_RadioGroup.SelectedIndex = selectedIndex
            Me.m_RadioGroup.SelectedIndexChanged += AddressOf OnRadioGroupSelectedIndexChanged
            Dim pairBox = NPairBox.Create("Size:", m_RadioGroup)
            pairBox.Box1.VerticalPlacement = ENVerticalPlacement.Top
            stack.Add(pairBox)

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

Nevron Open Vision provides support for drawing of vector based shapes called symbols. The advantage of such vector based shapes over regular raster images is that they do not blur and look nice at any size. This example demonstrates how to create and use custom symbols. Use the radio buttons on the right to see the symbols at different sizes.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Symbols", "https://www.nevron.com/docs/openvision/ui-symbols.html"), ("Widget Elements", "https://www.nevron.com/docs/openvision/ui-widget-elements.html")} End Function #End Region #Region "Implementation" Private Sub RecreateSymbols() Dim color = If(m_ColorBox IsNot Nothing, m_ColorBox.SelectedColor, DefaultSymbolColor) Dim length = If(m_RadioGroup IsNot Nothing, MinSymbolSize * Math.Pow(2, m_RadioGroup.SelectedIndex), DefaultSymbolSize) Dim size As NSize = New NSize(length, length) m_SymbolsTable.Clear() ' Create a triangle up symbol Dim shape As NPolygonSymbolShape = New NPolygonSymbolShape(New NPoint() {New NPoint(0, size.Height), New NPoint(size.Width * 0.5, 0), New NPoint(size.Width, size.Height)}, ENFillRule.EvenOdd) shape.Fill = New NColorFill(color) Dim symbol1 As NSymbol = New NSymbol() symbol1.Add(shape) AddSymbolBox(symbol1, "Triangle Up") ' Create a rectangle with an ellipse Dim rectShape As NRectangleSymbolShape = New NRectangleSymbolShape(0, 0, size.Width, size.Height) rectShape.Fill = New NColorFill(color) Dim ellipseShape As NEllipseSymbolShape = New NEllipseSymbolShape(size.Width / 4, size.Height / 4, size.Width / 2, size.Height / 2) ellipseShape.Fill = New NColorFill(color.Invert()) Dim symbol2 As NSymbol = New NSymbol() symbol2.Add(rectShape) symbol2.Add(ellipseShape) AddSymbolBox(symbol2, "Rectangle with an ellipse") End Sub Private Sub AddSymbolBox(symbol As NSymbol, name As String) m_SymbolsTable.Add(New NSymbolBox(symbol)) Dim label As NLabel = New NLabel(name) label.VerticalPlacement = ENVerticalPlacement.Center m_SymbolsTable.Add(label) End Sub #End Region #Region "Event Handlers" Private Sub OnColorBoxSelectedColorChanged(arg As NValueChangeEventArgs) RecreateSymbols() End Sub Private Sub OnRadioGroupSelectedIndexChanged(arg As NValueChangeEventArgs) RecreateSymbols() End Sub #End Region #Region "Fields" Private m_SymbolsTable As NTableFlowPanel Private m_ColorBox As NColorBox Private m_RadioGroup As NRadioButtonGroup #End Region #Region "Static Methods" #End Region #Region "Constants" Private Const MinSymbolSize As Double = 16 Private Const DefaultSymbolSize As Double = 32 Private Shared ReadOnly DefaultSymbolColor As NColor = NColor.MediumBlue #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Custom Symbols Example for WinForms Solution

Related Documentation Links