Buttons 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.

Buttons Example for WinForms Description

This example demonstrates the different types of buttons supported by NOV.


Buttons Example

C# Buttons 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 - NButtonsExample";

			// 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()
        {
            // create the host
            NStackPanel stack = new NStackPanel();
            stack.HorizontalPlacement = ENHorizontalPlacement.Left;
            stack.VerticalPlacement = ENVerticalPlacement.Top;
            stack.VerticalSpacing = 5;

            // text only push button
            NButton textOnlyButton = new NButton("Text only button");
            textOnlyButton.Click += OnButtonClicked;
            stack.Add(textOnlyButton);

            // image only push button
            NButton imageOnlyButton = new NButton(Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMAAAAAAABupgeRAAABu0lEQVR42sUPA6yQQfjuz7ZtN2ZzbMpNaYpTtjQvY0pz1lg927ZtHz50/9PY3PpsiH8O8vPvRKeImIiQEB07AIfdQB3Q0dDT8bZ1i8RfgNsZkH0l5Z4jV7yO1oKCgtOnT9+6dcvJsLAwa61fyT4BsUVHIioqoamlxUNEF713754rGDly5PTp0758/V5SWgYolGULPhlg7SR6Tc0tPQHQWFtUVAQAJ06cLCgszC8sMca0aP6RTMW1oq2VWttIado621Na9wTEHj16jh07Lig4KCExKTIsuKG2esqUySR441wGZAsCSGrrZWRL/2kAQBIXzp56dyomr7ho0pA+Y9JCC3KyR02anZVfExaTZSwBEiLNXzCuowGhpb74/q592zdE/rgxb2z/HCqPvbxp3YuiwUOHbt6wBJD9BuK8guKOBgCrualqqFSL580OCgxYOHl4dlZ1i6a0jMKikipjoKNn8rTJfgM66DvK23E/6u3+ct271cqf1UPHHX6kjJg2feL4ieNFFyRmVzkpH7z6sX7VUkCuadStClo1dqSZ2SBJZiBPg2egB0n58tnlnkR0+trdNq2V0sZa54r/DH8AtopTKVMOx+0AAAAASUVORK5CYII=")));
            imageOnlyButton.Click += OnButtonClicked;
            stack.Add(imageOnlyButton);

            // image and text button
            NImage image2 = Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACs0lEQVR4Aa2SA8wtRwBGz+xePtu2bSus7Tao7aBmVEW1bdvus237v76rUad2o/cli8E5Q8G/5IHnl/TMeP4juYyYDbEslaP37rz+HBfVcPPNGyx/yl8E9z21tHne46JmTdJ3jB+RpmfHEMI9rFpdYUNxgFy1cfeVqlR4/OabTw3+Irj5sS9zXZq2nJ7xvLub5LzBh8/Ik04nqFoFL9iPF29Cl3fxwc4j2Liz/KZo0uayy8+asB1APPDEkh7C98/o1FbcOnawT4f2GiKDTkKELCCCA4hwF7gHvZNdyWS+2zPEzF2+7+TmLdt+KR55dunanu1U/9mjKtC07f/C+F1BFtG17XwbXcji3W1eT6VTqf6zhy5F1ZvhBWVE7Kbs1i2S3WACLMoJI2QkMXI1SRjgmYDpmWtZqh87NmWBoJLg9TuG1N921gKJAe0e5R4Ta4xOKJRL1BdfwI4dB0lh4eONg5jaPiSX8dm9v0KzplmEEFgLBovwfIyxlKqSlq1aUIpCPtx83M99UsYY2nbpzxdzdzB7QhdatcjzyQ+7fga0/ukxaGXBCKZN68reAwf45vNN1LvMQe394hfB5GFtmJcWfL1oL77n0Tjnk836GPMTDArBwUKNL77YQakW4HXoRN/BHZk71/wiMMDAfq346oftjBrcmnHDOuE5kbFQk1CWgtZ1yVdfb2bXxiqTZ46mEoGSTuCmSNU9r7y1jsmjOzB8cDsH+kQGImVxnFuzdeUMfUf1JRAp5j8/FztmLFprnEDz4qtrGDagNYOHtKMWCwqRppoIlDFECURSuMeSSOjYq5e71pLK59872LpHaUaM7kzfPi1YX4A9ZaiEPuW6RUkPYwRBoB1sqQcGqSBo1JtaY0Wzov1lCd+9s4TPY0kcJURhTOL+ZSJRTm6t5bfY31/QDMshyY/gFJCcZo3GBQAAAABJRU5ErkJggg=="));
            NButton imageAndTextButton = new NButton(new NPairBox("Image before text", image2, ENPairBoxRelation.Box2BeforeBox1, false));
            imageAndTextButton.Click += OnButtonClicked;
            stack.Add(imageAndTextButton);

            // repeat button
            NRepeatButton repeatButton = new NRepeatButton("Repeat button");
            repeatButton.StartClicking += OnRepeatButtonStartClicking;
            repeatButton.Click += OnButtonClicked;
            repeatButton.EndClicking += OnRepeatButtonEndClicking;
            stack.Add(repeatButton);

            // toggle button
            NToggleButton toggleButton = new NToggleButton("Toggle button");
            toggleButton.Click += OnButtonClicked;
            stack.Add(toggleButton);

            // disabled button
            NButton disabledButton = new NButton("Disabled Button");
            disabledButton.Enabled = false;
            stack.Add(disabledButton);

            return stack;
        }
        public NWidget CreateExampleControls()
        {
            NStackPanel stack = new NStackPanel();
            stack.FillMode = ENStackFillMode.Last;
            stack.FitMode = ENStackFitMode.Last;

            // create the events list box
            m_EventsLog = new NExampleEventsLog();
            stack.Add(m_EventsLog);

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

This example demonstrates the different types of buttons supported by NOV.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Push Buttons", "https://www.nevron.com/docs/openvision/ui-push-buttons.html"), ("Buttons Overview", "https://www.nevron.com/docs/openvision/ui-buttons-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers private void OnButtonClicked(NEventArgs arg1) { m_EventsLog.LogEvent("Button clicked"); } private void OnRepeatButtonStartClicking(NEventArgs arg1) { m_EventsLog.LogEvent("Repeat Button Start Clicking"); } private void OnRepeatButtonEndClicking(NEventArgs arg1) { m_EventsLog.LogEvent("Repeat Button End Clicking"); } #endregion #region Fields private NExampleEventsLog m_EventsLog; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

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

VB.NET Buttons 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 - NButtonsExample"

        ' 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
            ' create the host
            Dim stack As NStackPanel = New NStackPanel()
            stack.HorizontalPlacement = ENHorizontalPlacement.Left
            stack.VerticalPlacement = ENVerticalPlacement.Top
            stack.VerticalSpacing = 5

            ' text only push button
            Dim textOnlyButton As NButton = New NButton("Text only button")
            textOnlyButton.Click += AddressOf OnButtonClicked
            stack.Add(textOnlyButton)

            ' image only push button
            Dim imageOnlyButton As NButton = New NButton(Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMAAAAAAABupgeRAAABu0lEQVR42sUPA6yQQfjuz7ZtN2ZzbMpNaYpTtjQvY0pz1lg927ZtHz50/9PY3PpsiH8O8vPvRKeImIiQEB07AIfdQB3Q0dDT8bZ1i8RfgNsZkH0l5Z4jV7yO1oKCgtOnT9+6dcvJsLAwa61fyT4BsUVHIioqoamlxUNEF713754rGDly5PTp0758/V5SWgYolGULPhlg7SR6Tc0tPQHQWFtUVAQAJ06cLCgszC8sMca0aP6RTMW1oq2VWttIado621Na9wTEHj16jh07Lig4KCExKTIsuKG2esqUySR441wGZAsCSGrrZWRL/2kAQBIXzp56dyomr7ho0pA+Y9JCC3KyR02anZVfExaTZSwBEiLNXzCuowGhpb74/q592zdE/rgxb2z/HCqPvbxp3YuiwUOHbt6wBJD9BuK8guKOBgCrualqqFSL580OCgxYOHl4dlZ1i6a0jMKikipjoKNn8rTJfgM66DvK23E/6u3+ct271cqf1UPHHX6kjJg2feL4ieNFFyRmVzkpH7z6sX7VUkCuadStClo1dqSZ2SBJZiBPg2egB0n58tnlnkR0+trdNq2V0sZa54r/DH8AtopTKVMOx+0AAAAASUVORK5CYII=")))
            imageOnlyButton.Click += AddressOf OnButtonClicked
            stack.Add(imageOnlyButton)

            ' image and text button
            Dim image2 As NImage = Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACs0lEQVR4Aa2SA8wtRwBGz+xePtu2bSus7Tao7aBmVEW1bdvus237v76rUad2o/cli8E5Q8G/5IHnl/TMeP4juYyYDbEslaP37rz+HBfVcPPNGyx/yl8E9z21tHne46JmTdJ3jB+RpmfHEMI9rFpdYUNxgFy1cfeVqlR4/OabTw3+Irj5sS9zXZq2nJ7xvLub5LzBh8/Ik04nqFoFL9iPF29Cl3fxwc4j2Liz/KZo0uayy8+asB1APPDEkh7C98/o1FbcOnawT4f2GiKDTkKELCCCA4hwF7gHvZNdyWS+2zPEzF2+7+TmLdt+KR55dunanu1U/9mjKtC07f/C+F1BFtG17XwbXcji3W1eT6VTqf6zhy5F1ZvhBWVE7Kbs1i2S3WACLMoJI2QkMXI1SRjgmYDpmWtZqh87NmWBoJLg9TuG1N921gKJAe0e5R4Ta4xOKJRL1BdfwI4dB0lh4eONg5jaPiSX8dm9v0KzplmEEFgLBovwfIyxlKqSlq1aUIpCPtx83M99UsYY2nbpzxdzdzB7QhdatcjzyQ+7fga0/ukxaGXBCKZN68reAwf45vNN1LvMQe394hfB5GFtmJcWfL1oL77n0Tjnk836GPMTDArBwUKNL77YQakW4HXoRN/BHZk71/wiMMDAfq346oftjBrcmnHDOuE5kbFQk1CWgtZ1yVdfb2bXxiqTZ46mEoGSTuCmSNU9r7y1jsmjOzB8cDsH+kQGImVxnFuzdeUMfUf1JRAp5j8/FztmLFprnEDz4qtrGDagNYOHtKMWCwqRppoIlDFECURSuMeSSOjYq5e71pLK59872LpHaUaM7kzfPi1YX4A9ZaiEPuW6RUkPYwRBoB1sqQcGqSBo1JtaY0Wzov1lCd+9s4TPY0kcJURhTOL+ZSJRTm6t5bfY31/QDMshyY/gFJCcZo3GBQAAAABJRU5ErkJggg=="))
            Dim imageAndTextButton As NButton = New NButton(New NPairBox("Image before text", image2, ENPairBoxRelation.Box2BeforeBox1, False))
            imageAndTextButton.Click += AddressOf OnButtonClicked
            stack.Add(imageAndTextButton)

            ' repeat button
            Dim repeatButton As NRepeatButton = New NRepeatButton("Repeat button")
            repeatButton.StartClicking += AddressOf OnRepeatButtonStartClicking
            repeatButton.Click += AddressOf OnButtonClicked
            repeatButton.EndClicking += AddressOf OnRepeatButtonEndClicking
            stack.Add(repeatButton)

            ' toggle button
            Dim toggleButton As NToggleButton = New NToggleButton("Toggle button")
            toggleButton.Click += AddressOf OnButtonClicked
            stack.Add(toggleButton)

            ' disabled button
            Dim disabledButton As NButton = New NButton("Disabled Button")
            disabledButton.Enabled = False
            stack.Add(disabledButton)

            Return stack
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()
            stack.FillMode = ENStackFillMode.Last
            stack.FitMode = ENStackFitMode.Last

            ' create the events list box
            m_EventsLog = New NExampleEventsLog()
            stack.Add(m_EventsLog)

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

This example demonstrates the different types of buttons supported by NOV.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Push Buttons", "https://www.nevron.com/docs/openvision/ui-push-buttons.html"), ("Buttons Overview", "https://www.nevron.com/docs/openvision/ui-buttons-overview.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnButtonClicked(arg1 As NEventArgs) m_EventsLog.LogEvent("Button clicked") End Sub Private Sub OnRepeatButtonStartClicking(arg1 As NEventArgs) m_EventsLog.LogEvent("Repeat Button Start Clicking") End Sub Private Sub OnRepeatButtonEndClicking(arg1 As NEventArgs) m_EventsLog.LogEvent("Repeat Button End Clicking") End Sub #End Region #Region "Fields" Private m_EventsLog As NExampleEventsLog #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) Buttons Example for WinForms Solution

Related Documentation Links