DocumentWindow context menu - keyboard shortcuts

2 posts, 0 answers
  1. Suresh G
    Suresh G avatar
    9 posts
    Member since:
    Mar 2012

    Posted 23 Apr 2013 Link to this post

    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
  2. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 26 Apr 2013 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top