In any case, for one particular program, I want to force the underscores to show all of the time, regardless of the user's setting. Now some may say that the choice should fall on the user and their preferred settings inside Windows, but in this particular case, it's an internal application that only a few of us will use, and I'm going to do it the way I want. :)
Windows API to the rescue... We can make a simple call to Windows unmanaged code to accomplish this task. Here's a sample of the code.
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int SystemParametersInfo(int uAction, int uParam, int lpvParam, int fuWinIni);
private const int SPI_SETKEYBOARDCUES = 4107; //100B
private const int SPIF_SENDWININICHANGE = 2;
[STAThread]
static void Main()
{
// always show accelerator underlines
SystemParametersInfo(SPI_SETKEYBOARDCUES, 0, 1, SPIF_SENDWININICHANGE);
Application.Run(new MainForm());
}

Hi Friend!! Just want to thank you for the code snippet!! You saved my ass!! Thanks!!
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis is great! Thank you for the info.
ReplyDelete