This example demonstrates how to add commanding interface to the NOV Diagram and how to switch between ribbon and command bars.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Diagram;
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 - NRibbonAndCommandBarsExample";
// 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 execute a ribbon UI builder
m_RibbonBuilder = new NDiagramRibbonBuilder();
return m_RibbonBuilder.CreateUI(m_DrawingView);
}
public NWidget CreateExampleControls()
{
// Switch UI button
NButton switchUIButton = new NButton(SwitchToCommandBars);
switchUIButton.VerticalPlacement = ENVerticalPlacement.Top;
switchUIButton.Click += OnSwitchUIButtonClick;
return switchUIButton;
}
public string GetExampleDescription()
{
return "This example demonstrates how to add commanding interface to the NOV Diagram and how to switch between ribbon and command bars.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Diagram Ribbon Overview", "https://www.nevron.com/docs/openvision/diagram-ribbon-overview.html"),
("Diagram Command Bars Overview", "https://www.nevron.com/docs/openvision/diagram-command-bars-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
private void SetUI(NCommandUIHolder oldUiHolder, NWidget widget)
{
if (oldUiHolder.ParentNode is NTabPage)
{
((NTabPage)oldUiHolder.ParentNode).Content = widget;
}
else if (oldUiHolder.ParentNode is NPairBox)
{
((NPairBox)oldUiHolder.ParentNode).Box1 = widget;
}
}
#endregion
#region Event Handlers
private void OnSwitchUIButtonClick(NEventArgs arg)
{
NButton switchUIButton = (NButton)arg.TargetNode;
NLabel label = (NLabel)switchUIButton.Content;
// Remove the drawing view from its parent
NCommandUIHolder uiHolder = m_DrawingView.GetFirstAncestor();
m_DrawingView.ParentNode.RemoveChild(m_DrawingView);
if (label.Text == SwitchToRibbon)
{
// We are in "Command Bars" mode, so switch to "Ribbon"
label.Text = SwitchToCommandBars;
// Create the ribbon
SetUI(uiHolder, m_RibbonBuilder.CreateUI(m_DrawingView));
}
else
{
// We are in "Ribbon" mode, so switch to "Command Bars"
label.Text = SwitchToRibbon;
// Create the command bars
if (m_CommandBarBuilder == null)
{
m_CommandBarBuilder = new NDiagramCommandBarBuilder();
}
SetUI(uiHolder, m_CommandBarBuilder.CreateUI(m_DrawingView));
}
}
#endregion
#region Fields
private NDrawingView m_DrawingView;
private NDiagramRibbonBuilder m_RibbonBuilder;
private NDiagramCommandBarBuilder m_CommandBarBuilder;
#endregion
#region Static Methods
#endregion
#region Constants
private const string SwitchToCommandBars = "Switch to Command Bars";
private const string SwitchToRibbon = "Switch to Ribbon";
#endregion
#region Nested Types
#endregion
}
}