Nevron Open Vision Documentation
Command Bars
Diagram Command Bar Builder

NOV Diagram provides a command bar builder that can be used to create some menus and toolbars to control and edit the drawing view and its shapes. This builder is represented by the class NDiagramCommandBarBuilder.

The easiest way to create a drawing view with command bars (menus and toolbars) is to use the NDrawingViewWithCommandBars class. The example below demonstrates how to create a drawing view with command bars hosted in a NOV widget host. You can then add this host to a form's Controls collection if you are creating a WinForms application, set it as the Content of a WPF window in a WPF application project or to the ContentView of a Xamarin.Mac window.

Create a Drawing View with Command Bars
Copy Code
NNovWidgetHost<NDrawingViewWithCommandBars> novContent = new NNovWidgetHost<NDrawingViewWithCommandBars>();

Another way to create a command bar based commanding UI and associate it with a drawing view is:

Create Command Bars UI
Copy Code
NDiagramCommandBarBuilder commandBarBuilder = new NDiagramCommandBarBuilder();
NWidget uiWidget = commandBarBuilder.CreateUI(drawingView);
Removing Commands

To remove all widgets associated with specific commands from the commanding UI, use the RemoveCommands method of the drawing view with command bars:

Remove commands
Copy Code
// Create an array of commands to remove
NCommand[] commandsToRemove = new NCommand[] {

NDrawingViewWithCommandBars drawingViewWithCommandBars = new NDrawingViewWithCommandBars();
Modifying Builder Collections

If you want to remove a given toolbar or menu from the builders, you can easily do so by using the Remove method of the ToolBarBuilders and MenuDropDownBuilders collection of the diagram command bar builder respectively. You can get or remove builders by name.

The names of all diagram menu and toolbar builders are exposed as constants in the NDiagramCommandBarBuilder class. For example, to remove the "File" menu and the "Standard" toolbar of a command bars based diagram UI, you can use the following piece of code:

Remove Toolbar and Menu Builders
Copy Code

In order to add or insert your own toolbar or menu drop down builder, you can use the Add or Insert methods of the corresponding builder collection respectively.

Add Custom Toolbar and Menu Builders
Copy Code
commandBarBuilder.MenuDropDownBuilders.Insert(1, new CustomMenuBuilder());
commandBarBuilder.ToolBarBuilders.Insert(0, new CustomToolBarBuilder());
Custom Menu Builders

To create a custom menu builder, you should create a class, which inherits NMenuDropDownBuilder:

Create custom menu drop down builder
Copy Code
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_png, NDrawingView.CopyCommand));

        // Add the custom command menu item
        items.Add(CreateMenuItem(NResources.Image_Ribbon_16x16_smiley_png, CustomCommand));
Custom Toolbar Builders

To create a custom toolbar builder, you should create a class, which inherits the NToolBarBuilder:

Create custom toolbar builder
Copy Code
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_png, NDrawingView.CopyCommand));

        // Add the custom command button
        items.Add(CreateButton(NResources.Image_Ribbon_16x16_smiley_png, CustomCommand));

To replace the original "Standard" toolbar builder with the custom one, use the following code:

Replace the "Standard" toolbar builder
Copy Code
NDiagramCommandBarBuilder commandBarBuilder = new NDiagramCommandBarBuilder();
int toolbarIndex = commandBarBuilder.ToolBarBuilders.IndexOf(NDiagramCommandBarBuilder.ToolbarStandardName);
commandBarBuilder.ToolBarBuilders[toolbarIndex] = new CustomStandardToolbar();
See Also


Send Feedback