Underscore in button text property does not show up
在我的C#WinForms程序中,我有一些按钮,并且为它们分配了一些快捷方式。快捷方式可以正常工作,但是在用户按下ALT键之前,按钮的text属性中的下划线不会显示。如何更改此默认行为?
这是我的下划线
1 | Button1.Text ="&EDIT"; |
谢谢。
我发现这篇文章使用了P / Invoke:
http://www.tompuleo.com/2010/05/force-c-to-always-show-keyboard.html
它说明了如何基于每个应用程序打开此行为。
通过链接:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [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()); } |
这是Windows的系统范围设置,与您的程序无关。