7

What's the point of adding mnemonic on a label control in C#?

I have a label with the text "&SomeText".

What event is triggered when i press ALT+S (I've tried OnClick but it's not fired)

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Gabriel
  • 1,435
  • 3
  • 17
  • 24

1 Answers1

9

The point of adding a mnemonic is to increase the accessibility of your app by reducing the reliance of a user on the mouse.

If you have a control that has a tabindex directly after the label, then invoking the mnemonic will fire the "enter" event on the control. You will notice the focus shift to this control.

So, the mnemonic is not for the label itself, but actually for the control next to it (+1 in the tab order).

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
James Wiseman
  • 29,946
  • 17
  • 95
  • 158
  • @Gabriel: Clarified in addendum to answer – James Wiseman Apr 20 '11 at 10:03
  • @James so basically it fires "OnEnter" event of the control that has the next tabindex? – Gabriel Apr 20 '11 at 10:07
  • @Gabriel: Yes. And, the enter even occurs when the con trol becomes the active control on the form. – James Wiseman Apr 20 '11 at 10:09
  • Thanks James for clarification – Gabriel Apr 20 '11 at 10:19
  • 3
    You technically have it backwards. The mnemonic causes the focus to be set to the next control in the tab order at a much lower level than the `Enter` event. The `Enter` event is raised as a *result* of the focus being changed; your answer makes it sound like this is inverted. But implementation details like this can and should be irrelevant to most. – Cody Gray - on strike Apr 20 '11 at 11:05