Add NOV Button control in WinForms at runtime

Add NOV Button control in WinForms at runtime

To get started and host NOV in your WinForms application, take a look at: Getting Started with NOV in WinForms using only code

The following code shows how to add a NOV Button Widget (control) in WinForms at runtime and raise the button click event, showing a message in NOV Message Box:

using Nevron.Nov;
using Nevron.Nov.Dom;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System.Windows.Forms;
namespace WindowsFormsApplication1
    public partial class Form1 : Form
        public Form1()
            // clear all controls from the form
            // create the host
            NStackPanel stack = new NStackPanel();
            stack.Margins = new Nevron.Nov.Graphics.NMargins(5);
            stack.HorizontalPlacement = ENHorizontalPlacement.Left;
            stack.VerticalPlacement = ENVerticalPlacement.Top;
            stack.HorizontalSpacing = 5;
            stack.VerticalSpacing = 5;
            // add  text only push button
            NButton textOnlyButton = new NButton("Text only button");
            textOnlyButton.Click += new Function<NEventArgs>(OnButtonClicked);
            Controls.Add(new NNovWidgetHost<NStackPanel>(stack));
        private void OnButtonClicked(NEventArgs arg1)
            NMessageBox.Show("textOnlyButton.Click was raised.", "NOV Message Box");

Run the application - it should display a simple form with a "Text only button" button inside. When you click the button, the click event will be raised and will display a message inside a NOV Message Box.

Using Visual Basic .NET (VB.NET)
When you create a Visual Basic Windows Forms Application, reference the NOV Assemblies and use the following code in your Form1.vb:

Imports Nevron.Nov
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Forms
Public Class Form1
    Inherits Form
    Public Sub New()
        ' clear all controls from the form
        ' TODO: Apply license for redistribution here. You can skip this code when evaluating NOV.
        NLicenseManager.Instance.SetLicense(New NLicense("LICENSE KEY"))
        ' Install Nevron Open Vision modules
        Dim modules() As NModule = {}
        ' create a stack panel
        Dim stack As New NStackPanel()
        stack.Margins = New Nevron.Nov.Graphics.NMargins(5)
        stack.HorizontalPlacement = ENHorizontalPlacement.Left
        stack.VerticalPlacement = ENVerticalPlacement.Top
        stack.HorizontalSpacing = 5
        stack.VerticalSpacing = 5
        ' add  text only push button
        Dim textOnlyButton As New NButton("Text only button")
        AddHandler textOnlyButton.Click, AddressOf textOnlyButton_Click
        ' create the host widget
        Dim host As New NNovWidgetHost(Of NStackPanel)(Stack)
        host.Dock = DockStyle.Fill
        ' add the host in the form controls
    End Sub
    Protected Sub textOnlyButton_Click(ByVal e As NEventArgs)
        NMessageBox.Show("textOnlyButton.Click was raised.", "NOV Message Box")
    End Sub
End Class

The NOV Message Box dialogue can replace the standard WinForm Message Box and it provides greater customization options.

For more information about the NOV Button and Message Box UI controls, take a look at the Help Documentation:
User Interface > Widgets > Buttons > Buttons Overview
User Interface > Dialogs > Message Box

Download Free Trial  Help Documentation
Send Feedback

Article ID: 243, Created On: 8/9/2016, Modified: 9/27/2016