In my C# WinForms programs I have some buttons and I have assigned some shourtcuts to them. the shortcuts work fine, but the underscore in the button's text property does not show up until the user hits ALT key. How can I change this default behaviour?
Well this is my underscore
Button1.Text = "&EDIT";
Thanks.
I found this article which uses P/Invoke:
http://www.tompuleo.com/2010/05/force-c-to-always-show-keyboard.html
It explains how to switch on this behaviour on a per-application basis.
From the link:
[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());
}
That's a system wide setting of Windows and has to do nothing with your program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With