Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.Text = "&EDIT";

Thanks.

like image 200
Saeid Yazdani Avatar asked May 05 '11 13:05

Saeid Yazdani


2 Answers

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());
}
like image 192
Nick Avatar answered Nov 14 '22 15:11

Nick


That's a system wide setting of Windows and has to do nothing with your program.

like image 30
Daniel Hilgarth Avatar answered Nov 14 '22 15:11

Daniel Hilgarth