Add NOV Button control in MonoMac project at runtime

Add NOV Button control in MonoMac project at runtime

To get started and host NOV in your Mac OS X (MonoMac) application, take a look at: Getting Started with NOV in MonoMac project

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

using System;
using Nevron.Nov.Mac;
using Nevron.Nov.UI;
using Nevron.Nov;
using Nevron.Nov.Dom;
using Nevron.Nov.Layout;
using Foundation;
using AppKit;
using MonoMac.Foundation;
using MonoMac.AppKit;
namespace MonoMacApplication1
    public partial class MainWindow : NSWindow
        #region Constructors
        // Called when created from unmanaged code
        public MainWindow(IntPtr handle)
            : base(handle)
        // Called when created directly from a XIB file
        public MainWindow(NSCoder coder)
            : base(coder)
        // Shared initialization code
        void Initialize()
            //NUISettings.EnableMultiThreadedPainting = false;
            //NUISettings.EnablePaintCache = false;
            NApplication.ApplyTheme(new NMacElCapitanTheme());
            // place the host inside the mac window
            // 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);
            this.ContentView = new NNovWidgetHost(stack);
        private void OnButtonClicked(NEventArgs arg1)
            NMessageBox.Show("textOnlyButton.Click was raised.", "NOV Message Box");

Run the application - it should display a simple Mac 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.

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: 249, Created On: 8/12/2016, Modified: 8/12/2016