Add NOV Button control in WPF at runtime

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

The following code shows how to add a NOV Button Widget (control) in WPF 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;
using System.Windows;
namespace WpfApplication1
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        public MainWindow()
            // Add a NOV widget inside 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);
            Content = 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 window 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 WPF Application, reference the NOV Assemblies and use the following code in your MainWindow.xaml.vb:

Imports Nevron.Nov
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows
Partial Public Class MainWindow
    Inherits Window
    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
        Content = New NNovWidgetHost(Of NStackPanel)(stack)
    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 WPF Message Box (System.Windows.MessageBox) 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: 245, Created On: 8/11/2016, Modified: 9/27/2016