Dumbo
Dumbo

Reputation: 14112

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.

Upvotes: 5

Views: 3172

Answers (2)

Nick
Nick

Reputation: 25799

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());
}

Upvotes: 6

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174309

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

Upvotes: 3

Related Questions