New to Telerik UI for WinForms? Download free 30-day trial

Using the CommandManager

Predefined Commands

  • DisplayQuickNavigator (CTRL+TAB): Displays the window activation tool (quick navigator)

  • CloseActiveDocument (CTRL+F4): Closes the currently active document and selects the next in the activation order list.

  • NextDocument (CTRL+F6): Sends the currently active document to the back of the activation order list and activates the next one.

  • PreviousDocument (CTRL+SHIFT+F6): Puts the last document in the activation order list in front and activates it.

The names of all predefined commands may be found in the static PredefinedCommandNames class.

Providing Custom Shortcuts

You may easily specify custom shortcut for any of the predefined commands like this:

private void ChangeNextDocumentShortcut()
{
    RadDockCommand command = this.radDock1.CommandManager.FindCommandByName(PredefinedCommandNames.NextDocument);
    command.Shortcuts.Clear();
    command.Shortcuts.Add(new RadShortcut(Keys.Shift, Keys.A, Keys.S));
}

The above code specifies the SHIFT+A+S as a valid key combination that will trigger the NextDocument command.

Registering Custom Command

The completely transparent object model of the command manager allows you to create and register completely custom command and associate it with the desired key combination. The following code demonstrates how to create custom command that floats the currently active tool window and is associated with the CTRL+F shortcut:

Define the custom command class

public class FloatWindowCommand : RadDockCommand
{
    public FloatWindowCommand()
    {
        this.Name = "FloatWindow";
        this.Shortcuts.Add(new RadShortcut(Keys.Control, Keys.F));
    }
    public override bool CanExecute(object parameter)
    {
        RadDock dock = parameter as RadDock;
        if (dock == null)
        {
            return false;
        }
        return dock.ActiveWindow is ToolWindow;
    }
    public override object Execute(params object[] settings)
    {
        RadDock dock = settings[0] as RadDock;
        Debug.Assert(dock != null, "Invalid execute parameter!");
        ToolWindow toolWindow = dock.ActiveWindow as ToolWindow;
        if (toolWindow != null)
        {
            dock.FloatWindow(toolWindow);
        }
        return base.Execute(settings);
    }  
}

Register the custom command

private void RegisterCustomCommand()
{
    this.radDock1.CommandManager.RegisterCommand(new FloatWindowCommand());
}

Enable/Disable the Command Manager

You may easily disable the command manager, using its Enabled property. Alternatively, you may either clear all commands or clear any shortcut associated with these commands.

See Also

Getting Started Understanding RadDock Using the ContextMenuService Using the DragDropService Document Manager