This example demonstrates how to customize the NOV diagram command bars (menus and toolbars).

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Diagram;
using Nevron.Nov.Diagram.DrawingCommands;
using Nevron.Nov.Diagram.Shapes;
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 - NCommandBarsCustomizationExample";
// 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 a simple drawing
m_DrawingView = new NDrawingView();
m_DrawingView.Document.HistoryService.Pause();
try
{
InitDiagram(m_DrawingView.Document);
}
finally
{
m_DrawingView.Document.HistoryService.Resume();
}
// Create and customize a command bar UI builder
m_CommandBarBuilder = new NDiagramCommandBarBuilder();
// Add the custom command action to the drawing view's commander
m_DrawingView.Commander.Add(new CustomCommandAction());
// Remove the "Edit" menu and insert a custom one
m_CommandBarBuilder = new NDiagramCommandBarBuilder();
m_CommandBarBuilder.MenuDropDownBuilders.Remove(NDiagramCommandBarBuilder.MenuEditName);
m_CommandBarBuilder.MenuDropDownBuilders.Insert(1, new CustomMenuBuilder());
// Remove the "Standard" toolbar and insert a custom one
m_CommandBarBuilder.ToolBarBuilders.Remove(NDiagramCommandBarBuilder.ToolBarStandardName);
m_CommandBarBuilder.ToolBarBuilders.Insert(0, new CustomToolBarBuilder());
// Create the commanding UI
NCommandUIHolder drawingViewWithCommandBars = m_CommandBarBuilder.CreateUI(m_DrawingView);
// Remove the Open command from the File menu and the page number command from the status bar
drawingViewWithCommandBars.RemoveCommands(NDrawingView.OpenCommand, NDrawingView.PageNumberStatusBarCommand);
return drawingViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
return null;
}
public string GetExampleDescription()
{
return @"
This example demonstrates how to customize the NOV diagram command bars (menus and toolbars).
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Diagram Command Bars via Code", "https://www.nevron.com/docs/openvision/diagram-command-bars-via-code.html"),
("Commanding Overview", "https://www.nevron.com/docs/openvision/diagram-commanding-overview.html"),
};
}
private void InitDiagram(NDrawingDocument drawingDocument)
{
NShape shape = new NBasicShapeFactory().CreateShape(ENBasicShape.Rectangle);
shape.SetBounds(100, 100, 150, 100);
drawingDocument.Content.ActivePage.Items.Add(shape);
}
#endregion
#region Implementation
#endregion
#region Event Handlers
#endregion
#region Fields
private NDrawingView m_DrawingView;
private NDiagramCommandBarBuilder m_CommandBarBuilder;
#endregion
#region Static Methods
#endregion
#region Constants
public static readonly NCommand CustomCommand = NCommand.Create(typeof(Nevron.Nov.Examples.Diagram.NCommandBarsCustomizationExample),
"CustomCommand", "Custom Command");
#endregion
#region Nested Types
public class CustomMenuBuilder : NMenuDropDownBuilder
{
public CustomMenuBuilder()
: base("Custom Menu")
{
}
protected override void AddItems(NMenuItemCollection items)
{
// Add the "Copy" menu item
items.Add(CreateMenuItem(Nevron.Nov.Presentation.NResources.Image_Edit_Copy_svg, NDrawingView.CopyCommand));
// Add the custom command menu item
items.Add(CreateMenuItem(Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABsElEQVR4AYWTQ7BjQRSGZz3cjM04Y9u2bdu2bdu29bx83jxzvI79z+munDiVW/Vd/Lf/g0aF0MvyeUJT4ipRTsDLb+ImoQ4zhJifEYjBp2jmfAJWAsmTYP/mN9m+SE08WfsVar7PZuPHcajfRI2M68NFEGn6+3wM6jZSovTRyMAgH9jcgDM5v0/E5+ODUbOBCgeX9oAnfiLccRNxf1c/qV3Z1Ed+B7SjFQHOsiAyplHmSjUUuLZZDoYMemKw1F4eHAjX96AAt7l3MIifIDOZP/k1D5kubuxDCcazxvwTAZyBoouyImUykDCJmMjISeTyA+EAbMbjvf1xaFlP7FrYHTvmS7B7UQ+cWNULj/f0o5bCA+Tyh8jSTKFGU4UGzZXBNCOtWm2FrCYgwB8R4DQL4ue2ud3QpLkGOp0uiGYUZM6YDkDipMAAN0WAOgQYN5XYv0crNGyqhoJMCpUGjZqp0am9HuaP42H9EtRCC94LN1m0EkiahDeHB2LNjC5YOaUzHu3uL6uzBZtfhe7G7KDV+M4rEHH2i0KPQlAlMXga60TW8U5sHuEkXEQBcYFoGDr+P5RkQoMvtntjAAAAAElFTkSuQmCC")), CustomCommand));
}
}
public class CustomToolBarBuilder : NToolBarBuilder
{
public CustomToolBarBuilder()
: base("Custom Toolbar")
{
}
protected override void AddItems(NCommandBarItemCollection items)
{
// Add the "Copy" button
items.Add(CreateButton(Nevron.Nov.Presentation.NResources.Image_Edit_Copy_svg, NDrawingView.CopyCommand));
// Add the custom command button
items.Add(CreateButton(Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABsElEQVR4AYWTQ7BjQRSGZz3cjM04Y9u2bdu2bdu29bx83jxzvI79z+munDiVW/Vd/Lf/g0aF0MvyeUJT4ipRTsDLb+ImoQ4zhJifEYjBp2jmfAJWAsmTYP/mN9m+SE08WfsVar7PZuPHcajfRI2M68NFEGn6+3wM6jZSovTRyMAgH9jcgDM5v0/E5+ODUbOBCgeX9oAnfiLccRNxf1c/qV3Z1Ed+B7SjFQHOsiAyplHmSjUUuLZZDoYMemKw1F4eHAjX96AAt7l3MIifIDOZP/k1D5kubuxDCcazxvwTAZyBoouyImUykDCJmMjISeTyA+EAbMbjvf1xaFlP7FrYHTvmS7B7UQ+cWNULj/f0o5bCA+Tyh8jSTKFGU4UGzZXBNCOtWm2FrCYgwB8R4DQL4ue2ud3QpLkGOp0uiGYUZM6YDkDipMAAN0WAOgQYN5XYv0crNGyqhoJMCpUGjZqp0am9HuaP42H9EtRCC94LN1m0EkiahDeHB2LNjC5YOaUzHu3uL6uzBZtfhe7G7KDV+M4rEHH2i0KPQlAlMXga60TW8U5sHuEkXEQBcYFoGDr+P5RkQoMvtntjAAAAAElFTkSuQmCC")), CustomCommand));
}
}
public class CustomCommandAction : NDrawingCommandAction
{
#region Constructors
///
/// Default constructor.
///
public CustomCommandAction()
{
}
///
/// Static constructor.
///
static CustomCommandAction()
{
CustomCommandActionSchema = NSchema.Create(typeof(CustomCommandAction), NDrawingCommandAction.NDrawingCommandActionSchema);
}
#endregion
#region Public Overrides
///
/// Gets the command associated with this command action.
///
///
public override NCommand GetCommand()
{
return CustomCommand;
}
///
/// Executes the command action.
///
///
///
public override void Execute(NNode target, object parameter)
{
NDrawingView drawingView = GetDrawingView(target);
NMessageBox.Show("Drawing Custom Command executed!", "Custom Command", ENMessageBoxButtons.OK,
ENMessageBoxIcon.Information);
}
#endregion
#region Schema
///
/// Schema associated with CustomCommandAction.
///
public static readonly NSchema CustomCommandActionSchema;
#endregion
}
#endregion
}
} | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.Diagram
Imports Nevron.Nov.Diagram.DrawingCommands
Imports Nevron.Nov.Diagram.Shapes
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Class MainWindow
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Title = "NOV WPF - NCommandBarsCustomizationExample"
' 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)
Content = host
End Sub
#End Region
#Region "Example"
Public Function CreateExampleContent() As NWidget
' Create a simple drawing
m_DrawingView = New NDrawingView()
m_DrawingView.Document.HistoryService.Pause()
Try
InitDiagram(m_DrawingView.Document)
Finally
m_DrawingView.Document.HistoryService.Resume()
End Try
' Create and customize a command bar UI builder
m_CommandBarBuilder = New NDiagramCommandBarBuilder()
' Add the custom command action to the drawing view's commander
m_DrawingView.Commander.Add(New CustomCommandAction())
' Remove the "Edit" menu and insert a custom one
m_CommandBarBuilder = New NDiagramCommandBarBuilder()
m_CommandBarBuilder.MenuDropDownBuilders.Remove(NDiagramCommandBarBuilder.MenuEditName)
m_CommandBarBuilder.MenuDropDownBuilders.Insert(1, New CustomMenuBuilder())
' Remove the "Standard" toolbar and insert a custom one
m_CommandBarBuilder.ToolBarBuilders.Remove(NDiagramCommandBarBuilder.ToolBarStandardName)
m_CommandBarBuilder.ToolBarBuilders.Insert(0, New CustomToolBarBuilder())
' Create the commanding UI
Dim drawingViewWithCommandBars = m_CommandBarBuilder.CreateUI(m_DrawingView)
' Remove the Open command from the File menu and the page number command from the status bar
drawingViewWithCommandBars.RemoveCommands(NDrawingView.OpenCommand, NDrawingView.PageNumberStatusBarCommand)
Return drawingViewWithCommandBars
End Function
Public Function CreateExampleControls() As NWidget
Return Nothing
End Function
Public Function GetExampleDescription() As String
Return "
This example demonstrates how to customize the NOV diagram command bars (menus and toolbars).
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Diagram Command Bars via Code", "https://www.nevron.com/docs/openvision/diagram-command-bars-via-code.html"), ("Commanding Overview", "https://www.nevron.com/docs/openvision/diagram-commanding-overview.html")}
End Function
Private Sub InitDiagram(drawingDocument As NDrawingDocument)
Dim shape As NShape = New NBasicShapeFactory().CreateShape(ENBasicShape.Rectangle)
shape.SetBounds(100, 100, 150, 100)
drawingDocument.Content.ActivePage.Items.Add(shape)
End Sub
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
#End Region
#Region "Fields"
Private m_DrawingView As NDrawingView
Private m_CommandBarBuilder As NDiagramCommandBarBuilder
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
Public Shared ReadOnly CustomCommand As NCommand = NCommand.Create(GetType(NCommandBarsCustomizationExample), "CustomCommand", "Custom Command")
#End Region
#Region "Nested Types"
Public Class CustomMenuBuilder
Inherits NMenuDropDownBuilder
Public Sub New()
MyBase.New("Custom Menu")
End Sub
Protected Overrides Sub AddItems(items As NMenuItemCollection)
' Add the "Copy" menu item
items.Add(CreateMenuItem(Presentation.NResources.Image_Edit_Copy_svg, NDrawingView.CopyCommand))
' Add the custom command menu item
items.Add(CreateMenuItem(Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABsElEQVR4AYWTQ7BjQRSGZz3cjM04Y9u2bdu2bdu29bx83jxzvI79z+munDiVW/Vd/Lf/g0aF0MvyeUJT4ipRTsDLb+ImoQ4zhJifEYjBp2jmfAJWAsmTYP/mN9m+SE08WfsVar7PZuPHcajfRI2M68NFEGn6+3wM6jZSovTRyMAgH9jcgDM5v0/E5+ODUbOBCgeX9oAnfiLccRNxf1c/qV3Z1Ed+B7SjFQHOsiAyplHmSjUUuLZZDoYMemKw1F4eHAjX96AAt7l3MIifIDOZP/k1D5kubuxDCcazxvwTAZyBoouyImUykDCJmMjISeTyA+EAbMbjvf1xaFlP7FrYHTvmS7B7UQ+cWNULj/f0o5bCA+Tyh8jSTKFGU4UGzZXBNCOtWm2FrCYgwB8R4DQL4ue2ud3QpLkGOp0uiGYUZM6YDkDipMAAN0WAOgQYN5XYv0crNGyqhoJMCpUGjZqp0am9HuaP42H9EtRCC94LN1m0EkiahDeHB2LNjC5YOaUzHu3uL6uzBZtfhe7G7KDV+M4rEHH2i0KPQlAlMXga60TW8U5sHuEkXEQBcYFoGDr+P5RkQoMvtntjAAAAAElFTkSuQmCC")), CustomCommand))
End Sub
End Class
Public Class CustomToolBarBuilder
Inherits NToolBarBuilder
Public Sub New()
MyBase.New("Custom Toolbar")
End Sub
Protected Overrides Sub AddItems(items As NCommandBarItemCollection)
' Add the "Copy" button
items.Add(MyBase.CreateButton(Presentation.NResources.Image_Edit_Copy_svg, NDrawingView.CopyCommand))
' Add the custom command button
items.Add(CreateButton(Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABsElEQVR4AYWTQ7BjQRSGZz3cjM04Y9u2bdu2bdu29bx83jxzvI79z+munDiVW/Vd/Lf/g0aF0MvyeUJT4ipRTsDLb+ImoQ4zhJifEYjBp2jmfAJWAsmTYP/mN9m+SE08WfsVar7PZuPHcajfRI2M68NFEGn6+3wM6jZSovTRyMAgH9jcgDM5v0/E5+ODUbOBCgeX9oAnfiLccRNxf1c/qV3Z1Ed+B7SjFQHOsiAyplHmSjUUuLZZDoYMemKw1F4eHAjX96AAt7l3MIifIDOZP/k1D5kubuxDCcazxvwTAZyBoouyImUykDCJmMjISeTyA+EAbMbjvf1xaFlP7FrYHTvmS7B7UQ+cWNULj/f0o5bCA+Tyh8jSTKFGU4UGzZXBNCOtWm2FrCYgwB8R4DQL4ue2ud3QpLkGOp0uiGYUZM6YDkDipMAAN0WAOgQYN5XYv0crNGyqhoJMCpUGjZqp0am9HuaP42H9EtRCC94LN1m0EkiahDeHB2LNjC5YOaUzHu3uL6uzBZtfhe7G7KDV+M4rEHH2i0KPQlAlMXga60TW8U5sHuEkXEQBcYFoGDr+P5RkQoMvtntjAAAAAElFTkSuQmCC")), CustomCommand))
End Sub
End Class
Public Class CustomCommandAction
Inherits NDrawingCommandAction
#Region "Constructors"
'''
''' Default constructor.
'''
Public Sub New()
End Sub
'''
''' Static constructor.
'''
Shared Sub New()
CustomCommandActionSchema = NSchema.Create(GetType(CustomCommandAction), NDrawingCommandActionSchema)
End Sub
#End Region
#Region "Public Overrides"
'''
''' Gets the command associated with this command action.
'''
'''
Public Overrides Function GetCommand() As NCommand
Return CustomCommand
End Function
'''
''' Executes the command action.
'''
'''
'''
Public Overrides Sub Execute(target As NNode, parameter As Object)
Dim drawingView = MyBase.GetDrawingView(target)
NMessageBox.Show("Drawing Custom Command executed!", "Custom Command", ENMessageBoxButtons.OK, ENMessageBoxIcon.Information)
End Sub
#End Region
#Region "Schema"
'''
''' Schema associated with CustomCommandAction.
'''
Public Shared ReadOnly CustomCommandActionSchema As NSchema
#End Region
End Class
#End Region
End Class