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

Shortcuts and Accelerator keys For RadMenuItem Issue

4 Answers 294 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Yongxiu
Top achievements
Rank 1
Yongxiu asked on 27 May 2013, 06:20 AM
Hi:
    I hope I can explain my problem clearly.

    When I add shortcuts and accelerator keys for RadMenuItem, I find some bugs or issues.

Step1: Add RadMenuItem "File". (Parent)
Step2: Add RadMenuItem "Open" (accelerator key is : O;  shortcut is : Ctrl + Shift + G)
Step3: Add RadMenuItem "Add"  (accelerator key is : A;  shortcut is : Alt + O)
Step4: Set "Add" is disabled.

Run the program, you can see the scene as the attachment below. Now, please enter "Alt + O",
the issues comes.....you can see it execute the "Open" function. Who can tell me why!!!!!
Is it mixed the shortcuts and accelerator keys ? is this a bug?

4 Answers, 1 is accepted

Sort by
0
Yongxiu
Top achievements
Rank 1
answered on 28 May 2013, 01:30 AM
BTW, I am using Telerik Winform Q2 2012 SP2.

Thanks a lot!
0
Ivan Petrov
Telerik team
answered on 29 May 2013, 05:10 PM
Hi Yongxiu,

Thank you for writing.

In your case you are mixing two concepts which are working simultaneously. One is mnemonics and the other one is shortcuts. When you place an & before a letter it will appear underlined in the menu item e.g. "&Open" appears as  "Open". When you press Alt + that letter the corresponding menu item will be executed. Shortcuts are another system which allows for fast execution of commands. As a general rule shortcuts do not include Alt + letter combinations. The Alt key is always accompanied by another modifier key e.g. Ctrl + Alt + F. This is exactly because mnemonics use the Alt key automatically. My suggestion would be that you follow this rule and change your shortcuts accordingly.

I hope this clears things up. Should you have further questions, I would be glad to help.

Regards,
Ivan Petrov
Telerik
RadChart for WinForms is obsolete. Now what?
0
Yongxiu
Top achievements
Rank 1
answered on 30 May 2013, 03:47 AM

I am glad to see your feedback. I just do another test following your suggestion, but the problem still exists. I will make a more detailed explanation to the problem here.

Under the "File" menu, two menu items are added, "&Open" without any shortcuts, and "&Add" with shortcuts "Ctrl + Shift + O".
Now the problem can be replicated by the flowing steps:
1. Click on "File" menu to popup the submenu.
2. Press "Ctrl + Shift + O"
In this case, you will see the procedure of  the "Open" menu is executed. This is very confused.
How can I avoid or walk around of the problem?

The code and the test program are attached for you to duplicate the problem.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls;
using System.Diagnostics;

namespace WindowsFormsApplication1
{
    public partial class Form1 : RadForm
    {
        private bool marked = true;

        public Form1()
        {
            InitializeComponent();

            this.radMenuItem1.DropDownOpening += new CancelEventHandler(radMenuItem1_DropDownOpening);
            this.radMenuItem1.DropDownClosing += new RadPopupClosingEventHandler(radMenuItem1_DropDownClosing);

            this.radMenuItem2.Click += new EventHandler(radMenuItem_Click);

            this.radMenuItem3.Shortcuts.Add(BuildRadShortcut(Keys.Control | Keys.Shift | Keys.O));
            this.radMenuItem3.Click += new EventHandler(radMenuItem_Click);          
        }

        void radMenuItem1_DropDownClosing(object sender, RadPopupClosingEventArgs args)
        {
            Debug.WriteLine("closing enter");

            marked = true;

            Debug.WriteLine(String.Format("marked value: {0}", marked));

            Debug.WriteLine("closing execution");
        }

        void radMenuItem1_DropDownOpening(object sender, CancelEventArgs e)
        {
            Debug.WriteLine("opening enter");

            marked = false;

            Debug.WriteLine(String.Format("marked value: {0}", marked));

            Debug.WriteLine("opening execution");
        }

        void radMenuItem_Click(object sender, EventArgs e)
        {
            Debug.WriteLine("clicked enter");
            var item = (RadMenuItem)sender;
            if (!item.Enabled)
            {
                return;
            }

            Debug.WriteLine(String.Format("marked value: {0}", marked));

            if (!marked)
            {
                Debug.WriteLine("clicked execution canceled");

                return;
            }

            Debug.WriteLine("click executed");

            MessageBox.Show("click " + ((RadMenuItem)(sender)).Text);
        }

        private static RadShortcut BuildRadShortcut(Keys shortcutKeys)
        {
            Keys modifiers = GetModifies(shortcutKeys);
            Keys letter = shortcutKeys ^ modifiers;

            return new RadShortcut(modifiers, letter);
        }

        private static Keys GetModifies(Keys combination)
        {
            // Set the actually assigned shortcut. The shortcut is a
            // combination of different Keys so they're bit-masked:
            bool ctrl = (combination & Keys.Control) == Keys.Control;
            bool alt = (combination & Keys.Alt) == Keys.Alt;
            bool shift = (combination & Keys.Shift) == Keys.Shift;

            Keys modifiers = Keys.None;
            if (ctrl) modifiers |= Keys.Control;
            if (alt) modifiers |= Keys.Alt;
            if (shift) modifiers |= Keys.Shift;

            return modifiers;
        }     
    }
}

0
Ivan Petrov
Telerik team
answered on 31 May 2013, 10:15 AM
Hello Yongxiu,

Thank you for writing back.

I was able to reproduce the issue you have described. There is an issue with the handling of the windows keyboard messages which is duplicating some of them. I have logged this case in our Public Issue Tracking System - PITS. You can track its progress, subscribe for status change alert and add your vote/comment to it on the following link - PITS Issue. Unfortunately I am not able to provide you with a workaround due to the nature of the issue.

I have updated your Telerik Points for bringing this case to our attention.

Should you have further questions, I would be glad to help.

Regards,
Ivan Petrov
Telerik
RadChart for WinForms is obsolete. Now what?
Tags
Menu
Asked by
Yongxiu
Top achievements
Rank 1
Answers by
Yongxiu
Top achievements
Rank 1
Ivan Petrov
Telerik team
Share this question
or