User Interface for .NET / User's Guide / Command Bars / Nested Commands

Nested Commands
 Overview
Nevron command model makes it very easy to create nested commands and drop-down menus. Actually, drop-down menus are created internally and the user does not deal directly with them. The concept is that each command that contains nested commands is responsible for creating and displaying a NMenuWindow control to visualize its children. This menu is created on demand - for example on a left mouse click. Using this approach, creation of complicated nested menus and command hierarchies is a matter of few lines of code.
 Creating Nested Commands

The following example demonstrates how to create nested commands:

C#
Copy Code
//create a NToolbar object first
NToolbar toolbar = new NToolbar();
toolbar.DefaultCommandStyle = CommandStyle.Text;

//create a file command and add it to the toolbar
NCommand fileCommand = new NCommand();
fileCommand.Properties.Text = "&File";
fileCommand.Properties.ShowArrowStyle = ShowArrowStyle.Never;

toolbar.Commands.Add(fileCommand);

//create some nested commands
NCommand saveCommand = new NCommand();
saveCommand.Properties.Text = "Save";

fileCommand.Commands.Add(saveCommand);

NCommand exitCommand = new NCommand();
exitCommand.Properties.Text = "E&xit";

fileCommand.Commands.Add(exitCommand);

NCommand saveAsCommand = new NCommand();
saveAsCommand.Properties.Text = "&Save As";

saveCommand.Commands.Add(saveAsCommand);

NCommand saveAllCommand = new NCommand();
saveAllCommand.Properties.Text = "Save &All";

saveCommand.Commands.Add(saveAllCommand);
Visual Basic
Copy Code
'create a NToolbar object first
Dim toolbar As NToolbar = New NToolbar()
toolbar.DefaultCommandStyle = CommandStyle.Text

'create a file command and add it to the toolbar
Dim fileCommand As NCommand = New NCommand()
fileCommand.Properties.Text = "&File"
fileCommand.Properties.ShowArrowStyle = ShowArrowStyle.Never

toolbar.Commands.Add(fileCommand)

'create some nested commands
Dim saveCommand As NCommand = New NCommand()
saveCommand.Properties.Text = "Save"

fileCommand.Commands.Add(saveCommand)

Dim exitCommand As NCommand = New NCommand()
exitCommand.Properties.Text = "E&xit"

fileCommand.Commands.Add(exitCommand)

Dim saveAsCommand As NCommand = New NCommand()
saveAsCommand.Properties.Text = "&Save As"

saveCommand.Commands.Add(saveAsCommand)

Dim saveAllCommand As NCommand = New NCommand()
saveAllCommand.Properties.Text = "Save &All"

saveCommand.Commands.Add(saveAllCommand)

The result from the example code above. 

See Also