Underscore in button text property does not show up
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.Te开发者_如何学编程xt = "&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.
精彩评论