Schedule Command Bars via Code
NOV Schedule provides two ways to create a schedule view with a command bars commanding UI.
The easiest way to create a command bar commanding UI for a schedule view is to use the NScheduleViewWithCommandBars widget or if you are not creating a cross-platform application - drop an NScheduleViewWithCommandBarsControl to a form/window using the Visual Studio Designer. You can then use the following approaches to modify the command bars:
1. Hiding Menus and Toolbars
To hide a command bar or a command bar item use the corresponding Get... method of the NScheduleViewWithCommandBars or NScheduleViewWithCommandBarsControl class and set its Visibility property to Collapsed:
- GetMainMenu - gets the main menu bar. When you get the menu bar, you can use it's FindMenuDropDownByText method to get a specific menu drop down. Then if you want to hide a specific menu item from the drop down menu, you can use the Items.FindByText method of the menu item, but if the menu item does not contain sub menu items, it's better to use the RemoveCommands method discussed in the next section.
- GetTooBar - gets a toolbar with a given name.
- GetStatusBar - gets the status bar.
The following code snippet hides the "View" menu and the "View" toolbar:
Hide menus and toolbars |
Copy Code
|
// Hide the "View" menu drop down
nScheduleViewWithCommandBarsControl1.GetMainMenuBar().FindMenuDropDownByText(NScheduleCommandBarBuilder.MenuViewName).Visibility = ENVisibility.Collapsed;
// Hide the "View" toolbar
nScheduleViewWithCommandBarsControl1.GetToolBar(NScheduleCommandBarBuilder.ToolbarViewName).Visibility = ENVisibility.Collapsed;
|
Note that instead of using string literals like "View", it is better to use the string constants defined in the NScheduleCommandBarBuilder class to get menu and toolbar names as shown in the code snippet above.
2. Removing Commands
To hide all widgets associated with specific commands from the commanding UI, use the RemoveCommands method of the schedule view with command bars. For example, the code snippet below removes the Open and Save commands and hides the widgets associated with them from the File menu:
Remove commands |
Copy Code
|
NScheduleViewWithCommandBars scheduleWithCommandBars = new NScheduleViewWithCommandBars();
scheduleViewWithCommandBars.RemoveCommands(NScheduleView.OpenCommand, NScheduleView.SaveCommand, NScheduleView.SaveAsCommand);
|
You can also create schedule command bars using the NScheduleCommandBarBuilder. This gives you greater flexibility and more ways to customize the NOV Schedule command bars, including an option to add custom commands to the command bars:
Creating a NOV Schedule command bar UI |
Copy Code
|
NScheduleCommandBarBuilder commandBarBuilder = new NScheduleCommandBarBuilder();
NCommandUIHolder scheduleWithCommandBars = commandBarBuilder.CreateUI(scheduleView);
|
1. 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 schedule command bar builder respectively. You can get or remove builders by name.
The names of all schedule menu and toolbar builders are exposed as constants in the NScheduleCommandBarBuilder class. For example, to remove the "File" menu and the "Standard" toolbar of a command bars based schedule UI, you can use the following piece of code:
Remove Toolbar and Menu Builders |
Copy Code
|
commandBarBuilder.MenuDropDownBuilders.Remove(NScheduleCommandBarBuilder.MenuFileName);
commandBarBuilder.ToolBarBuilders.Remove(NScheduleCommandBarBuilder.ToolbarStandardName);
|
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());
|
2. Removing commands
To hide all widgets associated with specific commands from the commanding UI, use the RemoveCommands method of the command UI holder created by the command bar builder. For example, the code snippet below removes the Open and Save commands and hides the widgets associated with them from the File menu:
Remove commands |
Copy Code
|
NScheduleCommandBarBuilder commandBarBuilder = new NScheduleCommandBarBuilder();
NCommandUIHolder scheduleViewWithCommandBars = commandBarBuilder.CreateUI(scheduleView);
scheduleViewWithCommandBars.RemoveCommands(NScheduleView.OpenCommand, NScheduleView.SaveCommand, NScheduleView.SaveAsCommand);
|
3. 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 "Add Appointment" menu item
items.Add(CreateMenuItem(Nevron.Nov.Schedule.NResources.Image_Edit_AddAppointment_png,
NScheduleView.AddAppointmentCommand));
// Add the custom command menu item
items.Add(CreateMenuItem(NResources.Image_Ribbon_16x16_smiley_png, CustomCommand));
}
}
|
4. 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 "Add Appointment" button
items.Add(CreateButton(Nevron.Nov.Schedule.NResources.Image_Edit_AddAppointment_png, NScheduleView.AddAppointmentCommand));
// 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
|
NScheduleCommandBarBuilder commandBarBuilder = new NScheduleCommandBarBuilder();
int toolbarIndex = commandBarBuilder.ToolBarBuilders.IndexOf(NScheduleCommandBarBuilder.ToolbarStandardName);
commandBarBuilder.ToolBarBuilders[toolbarIndex] = new CustomStandardToolbar();
|
To see how to define a custom command and a custom command action, take a look at the Schedule Commanding Overview topic.