User Panel 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.

User Panel Example for WinForms Description

This example demonstrates how to create a panel and how to add widgets to it. The example also shows how to assign expressions to some properties of the widgets so that they become anchored to the sides of the panel.


User Panel Example

C# User Panel 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.Windows.Forms;

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

		public Form1()
		{
			InitializeComponent();

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

			// 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()
		{
            NUserPanel panel = new NUserPanel();
			panel.HorizontalPlacement = ENHorizontalPlacement.Fit;
			panel.VerticalPlacement = ENVerticalPlacement.Fit;			

			// create a button that is anchored at the left-top
			// the button is sized to its desired size
			NButton button0 = new NButton("Anchor Left Top");
			button0.SetValue(NButton.XProperty, 10.0);
			button0.SetValue(NButton.YProperty, 10.0);
			button0.SetFx("Width", "DesiredWidth");
			button0.SetFx("Height", "DesiredHeight");
			panel.Add(button0);

			// create a button that is anchored at the right-top
			// the button is sized to its desired size, 
			// and the X is computed ralatively to the parent right side.
			NButton button1 = new NButton("Anchor Right Top");
			button1.SetFx("X", "$Parent.Width - Width - 10");
			button1.SetValue(NButton.YProperty, 10.0);
			button1.SetFx("Width", "DesiredWidth");
			button1.SetFx("Height", "DesiredHeight");
			panel.Add(button1);

			// create a button that is anchored at the right-bottom
			// the button is sized to its desired size, 
			// and the X and Y are computed ralatively to the parent right bottom sides.
			NButton button2 = new NButton("Anchor Right Bottom");
			button2.SetFx("X", "$Parent.Width - Width - 10");
			button2.SetFx("Y", "$Parent.Height - Height - 10");
			button2.SetFx("Width", "DesiredWidth");
			button2.SetFx("Height", "DesiredHeight");
			panel.Add(button2);

			// create a button that is anchored at the left-bottom
			// the button is sized to its desired size, 
			// and the Y is computed ralatively to the parent bottom side.
			NButton button3 = new NButton("Anchor Right Bottom");
			button3.SetValue(NButton.XProperty, 10.0);
			button3.SetFx("Y", "$Parent.Height - Height - 10");
			button3.SetFx("Width", "DesiredWidth");
			button3.SetFx("Height", "DesiredHeight");
			panel.Add(button3);

			// create a button which is anchored to inner corners of the other four buttons
			NButton button4 = new NButton("Anchor All");
			button4.SetFx("X", "MAX($Parent.0.X + $Parent.0.Width, $Parent.3.X + $Parent.3.Width)");
			button4.SetFx("Y", "MAX($Parent.0.Y + $Parent.0.Height, $Parent.1.Y + $Parent.1.Height)");
			button4.SetFx("Width", "MIN($Parent.1.X, $Parent.2.X) - X");
			button4.SetFx("Height", "MIN($Parent.2.Y, $Parent.3.Y) - Y");
			panel.Add(button4);

			return panel;
		}
		public NWidget CreateExampleControls()
		{
			return null;
		}
		public string GetExampleDescription()
		{
			return @"

This example demonstrates how to create a panel and how to add widgets to it. The example also shows how to assign expressions to some properties of the widgets so that they become anchored to the sides of the panel.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("User Panel", "https://www.nevron.com/docs/openvision/ui-panel.html"), ("Panels Overview", "https://www.nevron.com/docs/openvision/ui-panels-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) User Panel Example for WinForms Solution

VB.NET User Panel 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

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

        ' 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
            Dim panel As NUserPanel = New NUserPanel()
            panel.HorizontalPlacement = ENHorizontalPlacement.Fit
            panel.VerticalPlacement = ENVerticalPlacement.Fit

            ' create a button that is anchored at the left-top
            ' the button is sized to its desired size
            Dim button0 As NButton = New NButton("Anchor Left Top")
            button0.SetValue(NBoxElement.XProperty, 10.0)
            button0.SetValue(NBoxElement.YProperty, 10.0)
            button0.SetFx("Width", "DesiredWidth")
            button0.SetFx("Height", "DesiredHeight")
            panel.Add(button0)

            ' create a button that is anchored at the right-top
            ' the button is sized to its desired size, 
            ' and the X is computed ralatively to the parent right side.
            Dim button1 As NButton = New NButton("Anchor Right Top")
            button1.SetFx("X", "$Parent.Width - Width - 10")
            button1.SetValue(NBoxElement.YProperty, 10.0)
            button1.SetFx("Width", "DesiredWidth")
            button1.SetFx("Height", "DesiredHeight")
            panel.Add(button1)

            ' create a button that is anchored at the right-bottom
            ' the button is sized to its desired size, 
            ' and the X and Y are computed ralatively to the parent right bottom sides.
            Dim button2 As NButton = New NButton("Anchor Right Bottom")
            button2.SetFx("X", "$Parent.Width - Width - 10")
            button2.SetFx("Y", "$Parent.Height - Height - 10")
            button2.SetFx("Width", "DesiredWidth")
            button2.SetFx("Height", "DesiredHeight")
            panel.Add(button2)

            ' create a button that is anchored at the left-bottom
            ' the button is sized to its desired size, 
            ' and the Y is computed ralatively to the parent bottom side.
            Dim button3 As NButton = New NButton("Anchor Right Bottom")
            button3.SetValue(NBoxElement.XProperty, 10.0)
            button3.SetFx("Y", "$Parent.Height - Height - 10")
            button3.SetFx("Width", "DesiredWidth")
            button3.SetFx("Height", "DesiredHeight")
            panel.Add(button3)

            ' create a button which is anchored to inner corners of the other four buttons
            Dim button4 As NButton = New NButton("Anchor All")
            button4.SetFx("X", "MAX($Parent.0.X + $Parent.0.Width, $Parent.3.X + $Parent.3.Width)")
            button4.SetFx("Y", "MAX($Parent.0.Y + $Parent.0.Height, $Parent.1.Y + $Parent.1.Height)")
            button4.SetFx("Width", "MIN($Parent.1.X, $Parent.2.X) - X")
            button4.SetFx("Height", "MIN($Parent.2.Y, $Parent.3.Y) - Y")
            panel.Add(button4)

            Return panel
        End Function
        Public Function CreateExampleControls() As NWidget
            Return Nothing
        End Function
        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to create a panel and how to add widgets to it. The example also shows how to assign expressions to some properties of the widgets so that they become anchored to the sides of the panel.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("User Panel", "https://www.nevron.com/docs/openvision/ui-panel.html"), ("Panels Overview", "https://www.nevron.com/docs/openvision/ui-panels-overview.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" #End Region #Region "Fields" #End Region #Region "Static Methods" #End Region #Region "Constants" #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) User Panel Example for WinForms Solution

Related Documentation Links