Mnemonics – quick access keys that appear as underlined letters on buttons or menus and which are accessed by pressing the ALT key and the corresponding letter (the one underlined).
What’s the fuss about ? Well Microsoft decided that by default the underline does not appear on mnemonic enabled items. See: http://support.microsoft.com/kb/843329. In order to make the underline appear all the time you have these options:
- Go to Control Panel -> Display -> Appearance -> Effects and disable the checkbox Hide keyboard navigation indicators until I use the Alt key and then press OK.
- Modify a registry setting (you’ll have to digg this up somewhere else)
But we are programmers and we do not want our clients to mess up windows settings and/or registries. Thus we need a way to do it programatically.
WinAPI to the rescue !
The setting that we are talking about is modifiable by calling the SystemParametersInfo with certain parameters. Short version:
…
[DllImport("user32.dll")]
static extern Int32 SystemParametersInfo(uint uiAction, uint uiParam, ref bool pvParam, uint fWinIni);
private const int SPI_SETKEYBOARDCUES = 0x100B;
public MainForm()
{
InitializeComponent();
bool HotKey = true;
// HACK TO FORCE THE QUICK KEY SHOW UNDERLINE
SystemParametersInfo(SPI_SETKEYBOARDCUES, 0, ref HotKey, 0);}
}
…
In detail:
- include the System.Runtime.InteropServices namespace
- declare the external method SystemParameterInfo
- declare the SPI_SETKEYBOARDCUES constant
- call the SystemParameterInfo within the constructor of the main form.
Cya



Entries (RSS)
Awesome post, thank you. Is there a way to change it just for my application?
As far as I tested, the programatic sollution will only affect your application