This example demonstrates how to create and populate various types of command bars such as menu bars and toolbars.

| Language: C# |
using Nevron.Nov;
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 - NCommandBarsExample";
// 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()
{
NCommandBarManager manager = new NCommandBarManager();
// Create two lanes
NCommandBarLane lane0 = new NCommandBarLane();
manager.TopDock.Add(lane0);
NCommandBarLane lane1 = new NCommandBarLane();
manager.TopDock.Add(lane1);
NCommandBarLane lane2 = new NCommandBarLane();
manager.TopDock.Add(lane2);
NCommandBarLane lane3 = new NCommandBarLane();
manager.TopDock.Add(lane3);
// Create a menu bar in the first lane
NMenuBar menuBar = new NMenuBar();
lane0.Add(menuBar);
menuBar.Items.Add(CreateFileMenu());
menuBar.Items.Add(CreateEditMenu());
menuBar.Items.Add(CreateViewMenu());
menuBar.Text = "Main Menu";
// Create the File toolbar
NToolBar fileToolBar = new NToolBar();
lane1.Add(fileToolBar);
fileToolBar.Text = "File";
AddToolBarItem(fileToolBar, Nevron.Nov.Presentation.NResources.Image_File_New_svg, null, "New");
AddToolBarItem(fileToolBar, Nevron.Nov.Presentation.NResources.Image_File_Open_svg, null, "Open");
fileToolBar.Items.Add(new NCommandBarSeparator());
AddToolBarItem(fileToolBar, Nevron.Nov.Presentation.NResources.Image_File_Save_svg, null, "Save...");
AddToolBarItem(fileToolBar, Nevron.Nov.Presentation.NResources.Image_File_SaveAs_svg, null, "Save As...");
fileToolBar.Items.Add(new NCommandBarSeparator());
NButton executeButton = AddToolBarItem(fileToolBar, Nevron.Nov.Presentation.NResources.Image_Edit_Update_svg, "Execute");
executeButton.UserClass = NUITheme.UserClassAlert; // Make this an alert button (i.e. a red button)
// Create the Edit toolbar
NToolBar editToolBar = new NToolBar();
lane1.Add(editToolBar);
editToolBar.Text = "Edit";
AddToolBarItem(editToolBar, Nevron.Nov.Presentation.NResources.Image_Edit_Undo_svg, "Undo");
AddToolBarItem(editToolBar, Nevron.Nov.Presentation.NResources.Image_Edit_Redo_svg, "Redo");
editToolBar.Items.Add(new NCommandBarSeparator());
AddToolBarItem(editToolBar, Nevron.Nov.Presentation.NResources.Image_Edit_Copy_svg, "Copy");
AddToolBarItem(editToolBar, Nevron.Nov.Presentation.NResources.Image_Edit_Cut_svg, "Cut");
AddToolBarItem(editToolBar, Nevron.Nov.Presentation.NResources.Image_Edit_Paste_svg, "Paste");
// Create the View toolbar
NToolBar viewToolBar = new NToolBar();
lane1.Add(viewToolBar);
viewToolBar.Text = "View";
// Add toggle buttons in a toggle button group which acts like radio buttons.
AddToggleToolBarItem(viewToolBar, Nevron.Nov.Text.NResources.Image_Layout_Normal_svg, "Normal Layout");
AddToggleToolBarItem(viewToolBar, Nevron.Nov.Text.NResources.Image_Layout_Web_svg, "Web Layout");
AddToggleToolBarItem(viewToolBar, Nevron.Nov.Text.NResources.Image_Layout_Print_svg, "Print Layout");
viewToolBar.Items.Add(new NCommandBarSeparator());
AddToolBarItem(viewToolBar, null, "Task Pane");
AddToolBarItem(viewToolBar, null, "Toolbars");
AddToolBarItem(viewToolBar, null, "Ruller");
NToolBar toolbar = new NToolBar();
lane2.Add(toolbar);
toolbar.Text = "Toolbar";
toolbar.Wrappable = true;
NColorBox colorBoxItem = new NColorBox();
colorBoxItem.Tooltip = new NTooltip("Select Color");
NCommandBar.SetText(colorBoxItem, "Select Color");
toolbar.Items.Add(colorBoxItem);
NMenuSplitButton splitButton = new NMenuSplitButton();
splitButton.ActionButton.Content = NWidget.FromObject("Send/Receive");
splitButton.Menu.Items.Add(new NMenuItem("Send Receive All"));
splitButton.SelectedIndexChanged += OnSplitButtonSelectedIndexChanged;
splitButton.Menu.Items.Add(new NMenuItem("Send All"));
splitButton.Menu.Items.Add(new NMenuItem("Receive All"));
toolbar.Items.Add(splitButton);
// Add toggle button which enable/disables the next fill split button.
NToggleButton toggleButton = new NToggleButton("Enable");
toggleButton.CheckedChanged += OnToggleButtonCheckedChanged;
toolbar.Items.Add(toggleButton);
// Add fill split button
NFillSplitButton fillButton = new NFillSplitButton();
fillButton.Tooltip = new NTooltip("Select Fill");
fillButton.Enabled = false;
toolbar.Items.Add(fillButton);
// Add shadow split button
NShadowSplitButton shadowButton = new NShadowSplitButton();
shadowButton.Tooltip = new NTooltip("Select Shadow");
toolbar.Items.Add(shadowButton);
// Add stroke split button
NStrokeSplitButton strokeButton = new NStrokeSplitButton();
strokeButton.Tooltip = new NTooltip("Select Stroke");
toolbar.Items.Add(strokeButton);
manager.Content = new NLabel("Content Goes Here");
manager.Content.AllowFocus = true;
manager.Content.MouseDown += OnContentMouseDown;
manager.Content.Border = NBorder.CreateFilledBorder(NColor.Black);
manager.Content.BackgroundFill = new NColorFill(NColor.White);
manager.Content.BorderThickness = new NMargins(1);
manager.Content.GotFocus += OnContentGotFocus;
manager.Content.LostFocus += OnContentLostFocus;
return manager;
}
public NWidget CreateExampleControls()
{
return null;
}
public string GetExampleDescription()
{
return @"
This example demonstrates how to create and populate various types of command bars such as menu bars and toolbars.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Command Bars Overview", "https://www.nevron.com/docs/openvision/ui-command-bars-overview.html"),
("Toolbars", "https://www.nevron.com/docs/openvision/ui-toolbars.html"),
};
}
#endregion
#region Implementation
private NMenuDropDown CreateFileMenu()
{
NMenuDropDown file = new NMenuDropDown("File");
NMenuItem newMenuItem = CreateMenuItem("New", Presentation.NResources.Image_File_New_svg);
file.Items.Add(newMenuItem);
newMenuItem.Items.Add(new NMenuItem("Project"));
newMenuItem.Items.Add(new NMenuItem("Web Site"));
newMenuItem.Items.Add(new NMenuItem("File"));
NMenuItem openMenuItem = CreateMenuItem("Open", Presentation.NResources.Image_File_Open_svg);
file.Items.Add(openMenuItem);
openMenuItem.Items.Add(new NMenuItem("Project"));
openMenuItem.Items.Add(new NMenuItem("Web Site"));
openMenuItem.Items.Add(new NMenuItem("File"));
file.Items.Add(new NMenuSeparator());
file.Items.Add(CreateMenuItem("Save", Presentation.NResources.Image_File_Save_svg));
file.Items.Add(CreateMenuItem("Save As...", Presentation.NResources.Image_File_SaveAs_svg));
return file;
}
private NMenuDropDown CreateEditMenu()
{
NMenuDropDown edit = new NMenuDropDown("Edit");
edit.Items.Add(CreateMenuItem("Undo", Presentation.NResources.Image_Edit_Undo_svg));
edit.Items.Add(CreateMenuItem("Redo", Presentation.NResources.Image_Edit_Redo_svg));
edit.Items.Add(new NMenuSeparator());
edit.Items.Add(CreateMenuItem("Cut", Presentation.NResources.Image_Edit_Cut_svg));
edit.Items.Add(CreateMenuItem("Copy", Presentation.NResources.Image_Edit_Copy_svg));
edit.Items.Add(CreateMenuItem("Paste", Presentation.NResources.Image_Edit_Paste_svg));
return edit;
}
private NMenuDropDown CreateViewMenu()
{
NMenuDropDown view = new NMenuDropDown("View");
view.Items.Add(CreateCheckableMenuItem("Normal", Nov.Text.NResources.Image_Layout_Normal_svg));
view.Items.Add(CreateCheckableMenuItem("Web Layout", Nov.Text.NResources.Image_Layout_Web_svg));
view.Items.Add(CreateCheckableMenuItem("Print Layout", Nov.Text.NResources.Image_Layout_Print_svg));
view.Items.Add(new NMenuSeparator());
view.Items.Add(new NMenuItem("Task Pane"));
view.Items.Add(new NMenuItem("Toolbars"));
view.Items.Add(new NMenuItem("Ruler"));
return view;
}
private NToggleButton AddToggleToolBarItem(NToolBar toolBar, NImage image, string tooltip)
{
NToggleButton toggleButton = new NToggleButton(image);
toggleButton.Tooltip = new NTooltip(tooltip);
NCommandBar.SetText(toggleButton, tooltip);
NCommandBar.SetImage(toggleButton, image);
toolBar.Items.Add(toggleButton);
return toggleButton;
}
private NButton AddToolBarItem(NToolBar toolBar, NImage image, string text)
{
return AddToolBarItem(toolBar, image, text, text);
}
private NButton AddToolBarItem(NToolBar toolBar, NImage image, string text, string tooltip)
{
NButton button;
if (text == null)
{
text = string.Empty;
}
if (image == null)
{
button = new NButton(text);
}
else
{
button = new NButton(NPairBox.Create(image, text));
}
if (!string.IsNullOrEmpty(tooltip))
{
button.Tooltip = new NTooltip(tooltip);
}
toolBar.Items.Add(button);
NCommandBar.SetText(button, text);
if (image != null)
{
NCommandBar.SetImage(button, (NImage)image.DeepClone());
}
return button;
}
private NMenuItem CreateMenuItem(string text, NImage image)
{
if (image == null)
{
return new NMenuItem(text);
}
else
{
NImageBox imageBox = new NImageBox(image);
imageBox.HorizontalPlacement = ENHorizontalPlacement.Center;
imageBox.VerticalPlacement = ENVerticalPlacement.Center;
return new NMenuItem(imageBox, text);
}
}
private NCheckableMenuItem CreateCheckableMenuItem(string text, NImage image)
{
NCheckableMenuItem item = new NCheckableMenuItem(text);
item.CheckedChanging += item_CheckedChanging;
item.CheckedChanged += item_CheckedChanged;
if (image != null)
{
NImageBox imageBox = new NImageBox(image);
imageBox.HorizontalPlacement = ENHorizontalPlacement.Center;
imageBox.VerticalPlacement = ENVerticalPlacement.Center;
item.Header = imageBox;
item.Content = new NLabel(text);
}
return item;
}
#endregion
#region Event Handlers
private void OnContentLostFocus(NFocusChangeEventArgs args)
{
(args.TargetNode as NLabel).Border = NBorder.CreateFilledBorder(NColor.Black);
}
private void OnContentGotFocus(NFocusChangeEventArgs args)
{
(args.TargetNode as NLabel).Border = NBorder.CreateFilledBorder(NColor.Red);
}
private void OnContentMouseDown(NMouseButtonEventArgs args)
{
(args.TargetNode as NLabel).Focus();
}
private void OnSplitButtonSelectedIndexChanged(NValueChangeEventArgs arg)
{
NMenuSplitButton menuSplitButton = (NMenuSplitButton)arg.CurrentTargetNode;
NMenuItem menuItem = (NMenuItem)menuSplitButton.Items[menuSplitButton.SelectedIndex];
NLabel label = (NLabel)menuItem.Content;
menuSplitButton.ActionButton.Content = NWidget.FromObject(label.Text);
}
private void OnToggleButtonCheckedChanged(NValueChangeEventArgs arg)
{
NToggleButton button = arg.CurrentTargetNode as NToggleButton;
if (button == null)
{
return;
}
//Get the toolbar items collection and enable or disable the next button in the collection
NCommandBarItemCollection toolbarItems = button.ParentNode as NCommandBarItemCollection;
if (toolbarItems == null)
{
return;
}
int buttonIndex = toolbarItems.IndexOfChild(button);
NFillSplitButton fillSplitButton = toolbarItems[buttonIndex + 1] as NFillSplitButton;
if (fillSplitButton == null)
{
return;
}
if (button.Checked)
{
fillSplitButton.Enabled = true;
((NLabel)button.Content).Text = "Disable";
}
else
{
fillSplitButton.Enabled = false;
((NLabel)button.Content).Text = "Enable";
}
}
void item_CheckedChanging(NValueChangeEventArgs arg)
{
bool isChecked = (bool)arg.NewValue;
if (isChecked)
return;
// Make sure the user is not trying to uncheck the checked item
NCheckableMenuItem item = (NCheckableMenuItem)arg.TargetNode;
NMenuItemCollection items = item.ParentNode as NMenuItemCollection;
for (int i = 0, count = items.Count; i < count; i++)
{
NCheckableMenuItem currentItem = items[i] as NCheckableMenuItem;
if (currentItem == null)
{
continue;
}
if (currentItem != item && currentItem.Checked)
return;
}
arg.Cancel = true;
}
void item_CheckedChanged(NValueChangeEventArgs arg)
{
bool isChecked = (bool)arg.NewValue;
if (isChecked == false)
return;
NCheckableMenuItem item = (NCheckableMenuItem)arg.TargetNode;
NMenuItemCollection items = item.ParentNode as NMenuItemCollection;
for (int i = 0, count = items.Count; i < count; i++)
{
NCheckableMenuItem currentItem = items[i] as NCheckableMenuItem;
if (currentItem == null)
{
continue;
}
if (currentItem != item && currentItem.Checked)
{
// We've found the previously checked item, so uncheck it
currentItem.Checked = false;
break;
}
}
}
#endregion
#region Fields
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
} | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Forms
Public Class Form1
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Text = "NOV WinForms - NCommandBarsExample"
' 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)
host.Dock = DockStyle.Fill
Controls.Add(host)
End Sub
#End Region
#Region "Example"
Public Function CreateExampleContent() As NWidget
Dim manager As NCommandBarManager = New NCommandBarManager()
' Create two lanes
Dim lane0 As NCommandBarLane = New NCommandBarLane()
manager.TopDock.Add(lane0)
Dim lane1 As NCommandBarLane = New NCommandBarLane()
manager.TopDock.Add(lane1)
Dim lane2 As NCommandBarLane = New NCommandBarLane()
manager.TopDock.Add(lane2)
Dim lane3 As NCommandBarLane = New NCommandBarLane()
manager.TopDock.Add(lane3)
' Create a menu bar in the first lane
Dim menuBar As NMenuBar = New NMenuBar()
lane0.Add(menuBar)
menuBar.Items.Add(CreateFileMenu())
menuBar.Items.Add(CreateEditMenu())
menuBar.Items.Add(CreateViewMenu())
menuBar.Text = "Main Menu"
' Create the File toolbar
Dim fileToolBar As NToolBar = New NToolBar()
lane1.Add(fileToolBar)
fileToolBar.Text = "File"
AddToolBarItem(fileToolBar, Presentation.NResources.Image_File_New_svg, Nothing, "New")
AddToolBarItem(fileToolBar, Presentation.NResources.Image_File_Open_svg, Nothing, "Open")
fileToolBar.Items.Add(New NCommandBarSeparator())
AddToolBarItem(fileToolBar, Presentation.NResources.Image_File_Save_svg, Nothing, "Save...")
AddToolBarItem(fileToolBar, Presentation.NResources.Image_File_SaveAs_svg, Nothing, "Save As...")
fileToolBar.Items.Add(New NCommandBarSeparator())
Dim executeButton = AddToolBarItem(fileToolBar, Presentation.NResources.Image_Edit_Update_svg, "Execute")
executeButton.UserClass = NUITheme.UserClassAlert ' Make this an alert button (i.e. a red button)
' Create the Edit toolbar
Dim editToolBar As NToolBar = New NToolBar()
lane1.Add(editToolBar)
editToolBar.Text = "Edit"
AddToolBarItem(editToolBar, Presentation.NResources.Image_Edit_Undo_svg, "Undo")
AddToolBarItem(editToolBar, Presentation.NResources.Image_Edit_Redo_svg, "Redo")
editToolBar.Items.Add(New NCommandBarSeparator())
AddToolBarItem(editToolBar, Presentation.NResources.Image_Edit_Copy_svg, "Copy")
AddToolBarItem(editToolBar, Presentation.NResources.Image_Edit_Cut_svg, "Cut")
AddToolBarItem(editToolBar, Presentation.NResources.Image_Edit_Paste_svg, "Paste")
' Create the View toolbar
Dim viewToolBar As NToolBar = New NToolBar()
lane1.Add(viewToolBar)
viewToolBar.Text = "View"
' Add toggle buttons in a toggle button group which acts like radio buttons.
AddToggleToolBarItem(viewToolBar, Text.NResources.Image_Layout_Normal_svg, "Normal Layout")
AddToggleToolBarItem(viewToolBar, Text.NResources.Image_Layout_Web_svg, "Web Layout")
AddToggleToolBarItem(viewToolBar, Text.NResources.Image_Layout_Print_svg, "Print Layout")
viewToolBar.Items.Add(New NCommandBarSeparator())
AddToolBarItem(viewToolBar, Nothing, "Task Pane")
AddToolBarItem(viewToolBar, Nothing, "Toolbars")
AddToolBarItem(viewToolBar, Nothing, "Ruller")
Dim toolbar As NToolBar = New NToolBar()
lane2.Add(toolbar)
toolbar.Text = "Toolbar"
toolbar.Wrappable = True
Dim colorBoxItem As NColorBox = New NColorBox()
colorBoxItem.Tooltip = New NTooltip("Select Color")
NCommandBar.SetText(colorBoxItem, "Select Color")
toolbar.Items.Add(colorBoxItem)
Dim splitButton As NMenuSplitButton = New NMenuSplitButton()
splitButton.ActionButton.Content = NWidget.FromObject("Send/Receive")
splitButton.Menu.Items.Add(New NMenuItem("Send Receive All"))
splitButton.SelectedIndexChanged += AddressOf OnSplitButtonSelectedIndexChanged
splitButton.Menu.Items.Add(New NMenuItem("Send All"))
splitButton.Menu.Items.Add(New NMenuItem("Receive All"))
toolbar.Items.Add(splitButton)
' Add toggle button which enable/disables the next fill split button.
Dim toggleButton As NToggleButton = New NToggleButton("Enable")
toggleButton.CheckedChanged += AddressOf OnToggleButtonCheckedChanged
toolbar.Items.Add(toggleButton)
' Add fill split button
Dim fillButton As NFillSplitButton = New NFillSplitButton()
fillButton.Tooltip = New NTooltip("Select Fill")
fillButton.Enabled = False
toolbar.Items.Add(fillButton)
' Add shadow split button
Dim shadowButton As NShadowSplitButton = New NShadowSplitButton()
shadowButton.Tooltip = New NTooltip("Select Shadow")
toolbar.Items.Add(shadowButton)
' Add stroke split button
Dim strokeButton As NStrokeSplitButton = New NStrokeSplitButton()
strokeButton.Tooltip = New NTooltip("Select Stroke")
toolbar.Items.Add(strokeButton)
manager.Content = New NLabel("Content Goes Here")
manager.Content.AllowFocus = True
manager.Content.MouseDown += AddressOf OnContentMouseDown
manager.Content.Border = NBorder.CreateFilledBorder(NColor.Black)
manager.Content.BackgroundFill = New NColorFill(NColor.White)
manager.Content.BorderThickness = New NMargins(1)
manager.Content.GotFocus += AddressOf OnContentGotFocus
manager.Content.LostFocus += AddressOf OnContentLostFocus
Return manager
End Function
Public Function CreateExampleControls() As NWidget
Return Nothing
End Function
Public Function GetExampleDescription() As String
Return "
This example demonstrates how to create and populate various types of command bars such as menu bars and toolbars.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Command Bars Overview", "https://www.nevron.com/docs/openvision/ui-command-bars-overview.html"), ("Toolbars", "https://www.nevron.com/docs/openvision/ui-toolbars.html")}
End Function
#End Region
#Region "Implementation"
Private Function CreateFileMenu() As NMenuDropDown
Dim file As NMenuDropDown = New NMenuDropDown("File")
Dim newMenuItem = CreateMenuItem("New", Presentation.NResources.Image_File_New_svg)
file.Items.Add(newMenuItem)
newMenuItem.Items.Add(New NMenuItem("Project"))
newMenuItem.Items.Add(New NMenuItem("Web Site"))
newMenuItem.Items.Add(New NMenuItem("File"))
Dim openMenuItem = CreateMenuItem("Open", Presentation.NResources.Image_File_Open_svg)
file.Items.Add(openMenuItem)
openMenuItem.Items.Add(New NMenuItem("Project"))
openMenuItem.Items.Add(New NMenuItem("Web Site"))
openMenuItem.Items.Add(New NMenuItem("File"))
file.Items.Add(New NMenuSeparator())
file.Items.Add(CreateMenuItem("Save", Presentation.NResources.Image_File_Save_svg))
file.Items.Add(CreateMenuItem("Save As...", Presentation.NResources.Image_File_SaveAs_svg))
Return file
End Function
Private Function CreateEditMenu() As NMenuDropDown
Dim edit As NMenuDropDown = New NMenuDropDown("Edit")
edit.Items.Add(CreateMenuItem("Undo", Presentation.NResources.Image_Edit_Undo_svg))
edit.Items.Add(CreateMenuItem("Redo", Presentation.NResources.Image_Edit_Redo_svg))
edit.Items.Add(New NMenuSeparator())
edit.Items.Add(CreateMenuItem("Cut", Presentation.NResources.Image_Edit_Cut_svg))
edit.Items.Add(CreateMenuItem("Copy", Presentation.NResources.Image_Edit_Copy_svg))
edit.Items.Add(CreateMenuItem("Paste", Presentation.NResources.Image_Edit_Paste_svg))
Return edit
End Function
Private Function CreateViewMenu() As NMenuDropDown
Dim view As NMenuDropDown = New NMenuDropDown("View")
view.Items.Add(CreateCheckableMenuItem("Normal", Text.NResources.Image_Layout_Normal_svg))
view.Items.Add(CreateCheckableMenuItem("Web Layout", Text.NResources.Image_Layout_Web_svg))
view.Items.Add(CreateCheckableMenuItem("Print Layout", Text.NResources.Image_Layout_Print_svg))
view.Items.Add(New NMenuSeparator())
view.Items.Add(New NMenuItem("Task Pane"))
view.Items.Add(New NMenuItem("Toolbars"))
view.Items.Add(New NMenuItem("Ruler"))
Return view
End Function
Private Function AddToggleToolBarItem(toolBar As NToolBar, image As NImage, tooltip As String) As NToggleButton
Dim toggleButton As NToggleButton = New NToggleButton(image)
toggleButton.Tooltip = New NTooltip(tooltip)
NCommandBar.SetText(toggleButton, tooltip)
NCommandBar.SetImage(toggleButton, image)
toolBar.Items.Add(toggleButton)
Return toggleButton
End Function
Private Function AddToolBarItem(toolBar As NToolBar, image As NImage, text As String) As NButton
Return AddToolBarItem(toolBar, image, text, text)
End Function
Private Function AddToolBarItem(toolBar As NToolBar, image As NImage, text As String, tooltip As String) As NButton
Dim button As NButton
If Equals(text, Nothing) Then
text = String.Empty
End If
If image Is Nothing Then
button = New NButton(text)
Else
button = New NButton(NPairBox.Create(image, text))
End If
If Not String.IsNullOrEmpty(tooltip) Then
button.Tooltip = New NTooltip(tooltip)
End If
toolBar.Items.Add(button)
NCommandBar.SetText(button, text)
If image IsNot Nothing Then
Call NCommandBar.SetImage(button, CType(image.DeepClone(), NImage))
End If
Return button
End Function
Private Function CreateMenuItem(text As String, image As NImage) As NMenuItem
If image Is Nothing Then
Return New NMenuItem(text)
Else
Dim imageBox As NImageBox = New NImageBox(image)
imageBox.HorizontalPlacement = ENHorizontalPlacement.Center
imageBox.VerticalPlacement = ENVerticalPlacement.Center
Return New NMenuItem(imageBox, text)
End If
End Function
Private Function CreateCheckableMenuItem(text As String, image As NImage) As NCheckableMenuItem
Dim item As NCheckableMenuItem = New NCheckableMenuItem(text)
item.CheckedChanging += AddressOf item_CheckedChanging
item.CheckedChanged += AddressOf item_CheckedChanged
If image IsNot Nothing Then
Dim imageBox As NImageBox = New NImageBox(image)
imageBox.HorizontalPlacement = ENHorizontalPlacement.Center
imageBox.VerticalPlacement = ENVerticalPlacement.Center
item.Header = imageBox
item.Content = New NLabel(text)
End If
Return item
End Function
#End Region
#Region "Event Handlers"
Private Sub OnContentLostFocus(args As NFocusChangeEventArgs)
TryCast(args.TargetNode, NLabel).Border = NBorder.CreateFilledBorder(NColor.Black)
End Sub
Private Sub OnContentGotFocus(args As NFocusChangeEventArgs)
TryCast(args.TargetNode, NLabel).Border = NBorder.CreateFilledBorder(NColor.Red)
End Sub
Private Sub OnContentMouseDown(args As NMouseButtonEventArgs)
TryCast(args.TargetNode, NLabel).Focus()
End Sub
Private Sub OnSplitButtonSelectedIndexChanged(arg As NValueChangeEventArgs)
Dim menuSplitButton = CType(arg.CurrentTargetNode, NMenuSplitButton)
Dim menuItem = CType(menuSplitButton.Items(menuSplitButton.SelectedIndex), NMenuItem)
Dim label = CType(menuItem.Content, NLabel)
menuSplitButton.ActionButton.Content = NWidget.FromObject(label.Text)
End Sub
Private Sub OnToggleButtonCheckedChanged(arg As NValueChangeEventArgs)
Dim button As NToggleButton = TryCast(arg.CurrentTargetNode, NToggleButton)
If button Is Nothing Then
Return
End If
'Get the toolbar items collection and enable or disable the next button in the collection
Dim toolbarItems As NCommandBarItemCollection = TryCast(button.ParentNode, NCommandBarItemCollection)
If toolbarItems Is Nothing Then
Return
End If
Dim buttonIndex = toolbarItems.IndexOfChild(button)
Dim fillSplitButton As NFillSplitButton = TryCast(toolbarItems(buttonIndex + 1), NFillSplitButton)
If fillSplitButton Is Nothing Then
Return
End If
If button.Checked Then
fillSplitButton.Enabled = True
CType(button.Content, NLabel).Text = "Disable"
Else
fillSplitButton.Enabled = False
CType(button.Content, NLabel).Text = "Enable"
End If
End Sub
Private Sub item_CheckedChanging(arg As NValueChangeEventArgs)
Dim isChecked As Boolean = arg.NewValue
If isChecked Then Return
' Make sure the user is not trying to uncheck the checked item
Dim item = CType(arg.TargetNode, NCheckableMenuItem)
Dim items As NMenuItemCollection = TryCast(item.ParentNode, NMenuItemCollection)
Dim i = 0, count = items.Count
While i < count
Dim currentItem As NCheckableMenuItem = TryCast(items(i), NCheckableMenuItem)
If currentItem Is Nothing Then
Continue While
End If
If currentItem IsNot item AndAlso currentItem.Checked Then Return
i += 1
End While
arg.Cancel = True
End Sub
Private Sub item_CheckedChanged(arg As NValueChangeEventArgs)
Dim isChecked As Boolean = arg.NewValue
If isChecked = False Then Return
Dim item = CType(arg.TargetNode, NCheckableMenuItem)
Dim items As NMenuItemCollection = TryCast(item.ParentNode, NMenuItemCollection)
Dim i = 0, count = items.Count
While i < count
Dim currentItem As NCheckableMenuItem = TryCast(items(i), NCheckableMenuItem)
If currentItem Is Nothing Then
Continue While
End If
If currentItem IsNot item AndAlso currentItem.Checked Then
' We've found the previously checked item, so uncheck it
currentItem.Checked = False
Exit While
End If
i += 1
End While
End Sub
#End Region
#Region "Fields"
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class