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

Keyboard access to the menu items

3 Answers 106 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 12 Dec 2017, 11:39 AM

Hi,

I have a Form with a RadMenu added to it (using form.Controls.Add (menu), and the menu is configured as :

 

Dim item As RadMenuItem = New RadMenuItem
item.Name = "Test"
item.Text = "Test"
item.Shortcuts.Add(item:=New RadShortcut(Keys.Alt, Keys.T))

Dim mOption As RadMenuItem = New RadMenuItem
mOption.Name = "Go"
mOption.Text = "Go"

item.Items.Add(value:=mOption)

menu.Items.Add(item)

This correctly displays the menu at the top of the form as "Test ALT + T", but I am expecting the Alt + T keypress to dropdown the menu to show the "Go" option, but this isn't happening.

Am I using this incorrectly?

Actually, the reason I am looking to use ShortCuts in this way is our existing app currently uses the "&" notation to provide keyboard access to the menu, so the example above would be "&Test" and this would correctly dropdown down on ALT + T.

The reason we are looking to move to shortcuts is we have an issue with the menu retaining focus on a non-existing Alt + KEY combo which is causing us problems.

E.g,

If the user types Alt + Z nothing happens, which is correct as there is no ALT + | menu item.

Now if the uses types T without ALT, we would like the T the keypress to be processed by the form and not the menu, unless ALT is pressed again.

We are finding though that the menu is still snagging the T keypress and dropping down the Test menu, which is not what we want.

Is there an alternate approach we can use to avoid this?

Mark

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 13 Dec 2017, 11:38 AM
Hello, Mark,

Thank you for writing.  

The RadMenuItem.Click event is fired when you press Alt+T keys. However, the drop-down menu is shown when handling the MouseDown message. That is why in this case the shortcut doesn't show the popup. You can manually show the drop-down in the RadMenuItem.Click event by using the following code snippet:
Sub New()
      
    InitializeComponent()
 
    Dim item As RadMenuItem = New RadMenuItem
    item.Name = "Test"
    item.Text = "Test"
    AddHandler item.Click, AddressOf ItemClick 
 
    item.Shortcuts.Add(New RadShortcut(Keys.Alt, Keys.T))
     
    Dim mOption As RadMenuItem = New RadMenuItem
    mOption.Name = "Go"
    mOption.Text = "Go"
 
    item.Items.Add(value:=mOption)
 
    Me.RadMenu1.Items.Add(item)
 
End Sub
 
Private Sub ItemClick(sender As Object, e As EventArgs)
    Console.WriteLine(DateTime.Now.ToLongTimeString())
    Dim item As RadMenuItem = TryCast(sender, RadMenuItem)
    item.ShowChildItems()
End Sub

I hope this information helps. Should you have further questions I would be glad to help.
 
Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Mark
Top achievements
Rank 1
answered on 13 Dec 2017, 04:27 PM

Great stuff. This works a treat.

A couple of follow on questions if that is OK?

Firstly, we are looking to use Shortcuts is to avoid the problem with the menu persisting focus once the "ALT" key has been pressed with the "&" labels, so if the first key combo is not a hit on a menu item, the menu then selects the menu item for the next keypress if it matches when ALT is not pressed the 2nd time.

Can this behaviour be avoided using the "&Test" notation?

If not, is there any way to replicate the underscore key indicator using Shortcuts? the ALT + T suffix to show the shortcut is a bit clunky for us and it would be great if we could underscore the T as would happen with &Test,

Is this possible?

 

Many thanks,

Mark.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 14 Dec 2017, 02:41 PM
Hello, Mark, 

Thank you for writing back. 

The UseMnemonic property is relevant for a few controls only. In order to make the "T" letter with an underscore it is necessary to use HTML-like text formatting:
Dim item As RadMenuItem = New RadMenuItem
item.Name = "T"
AddHandler item.Click, AddressOf ItemClick
item.Shortcuts.Add(New RadShortcut(Keys.Alt, Keys.T))
item.Text = "<html><u>T"
Dim t As TextPrimitive = TryCast(item.Layout.FindDescendant(Of TextPrimitive)(), TextPrimitive)
t.ForeColor = Color.Transparent ' hide the shortcut keys

When the user holds the Alt key pressed and then hits some other key which doesn't form a mnemonic, if then he hits another key (which is a mnemonic) while the Alt is still pressed, the Click event for the respective menu item will be triggered. If I understand your requirement correctly, you are trying to avoid this behavior. I think that global shortcuts may be suitable for your case. Thus, you can create your own IShortcutProvider and control what action to be performed when a shortcut is executed. You add the shortcuts to the provider itself, not to the RadMenuItems. Additional information is available in the following help article: https://docs.telerik.com/devtools/winforms/shortcuts/assigning-global-radshortcuts

However, if it is not the exact case, it would be greatly appreciated if you can specify in details what is the exact requirement that you are trying to achieve. Thus, we would be able to think about a suitable solution and assist you further. Thank you in advance.

I hope this information helps. If you have any additional questions, please let me know. 

 Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Menu
Asked by
Mark
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Mark
Top achievements
Rank 1
Share this question
or