This is a migrated thread and some comments may be shown as answers.

DocumentWindow context menu - keyboard shortcuts

1 Answer 87 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Mahesh V
Top achievements
Rank 2
Mahesh V asked on 23 Apr 2013, 07:09 AM
In raddock, i open a form in new tab. Right click on tab and context menu opens. I want to know is it possible to add keyboard shortcuts for different options available in menu. For example, I want to add keyboard shortcut for New Vertical Tab Group.

PFA

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 26 Apr 2013, 07:25 AM
Hello Santhosh,

Thank you for writing.

This scenario is not supported out of the box because these Context Menu items are create dynamically every time when the context menu is opening.

However, you can use a global shortcuts. For example:
public class MyShortcutProvider : IShortcutProvider
{
    private RadShortcutCollection shortcuts;
    private bool registered;
    private RadDock ownerDock;
    public MyShortcutProvider(RadDock ownerDock)
    {
        this.shortcuts = new RadShortcutCollection(this);
        this.ownerDock = ownerDock;
    }
     
    public void OnPartialShortcut(PartialShortcutEventArgs e)
    {        
        e.Handled = true;
    }
 
    public void OnShortcut(ShortcutEventArgs e)
    {
        //A keyboard combination for a specific shortcut is pressed.
        MessageBox.Show("Shortcut [" + e.Shortcut.GetDisplayText() + "] is executed.");
        if (e.Shortcut.KeyMappings[0] == Keys.C)
        {
            if (this.ownerDock.ActiveWindow != null)
            {
 
                this.ownerDock.ActiveWindow.Close();
            }
        }
        //Mark the event arguments as "Handled" so that this shortcut is no further processed.
        e.Handled = true;
    }
 
    public void OnShortcutsChanged()
    {        
        if (this.shortcuts.Count > 0)
        {
            if (!this.registered)
            {
                RadShortcutManager.Instance.AddShortcutProvider(this);
                this.registered = true;
            }
        }
        else
        {
            if (this.registered)
            {
                RadShortcutManager.Instance.RemoveShortcutProvider(this);
                this.registered = false;
            }
        }
    }
 
    public RadShortcutCollection Shortcuts
    {
        get
        {
            return this.shortcuts;
        }
    } 
}
 
    public Form1()
    {
        InitializeComponent();
             
        MyShortcutProvider provider = new MyShortcutProvider(this.radDock1);
        provider.Shortcuts.Add(new RadShortcut(Keys.Control, Keys.C));//this short cut should close active window

I hope this helps.

All the best,
Peter
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Tags
Dock
Asked by
Mahesh V
Top achievements
Rank 2
Answers by
Peter
Telerik team
Share this question
or