35

I would like to show the & character, not the keyboard shortcut in the text property of a button or label.

Is there a way to do this?

AStopher
  • 4,207
  • 11
  • 50
  • 75
atrueresistance
  • 1,358
  • 5
  • 26
  • 48
  • 1
    Possible duplicate of *[Enter "&" symbol into a text Label in Windows Forms?](http://stackoverflow.com/questions/4325094/enter-symbol-into-a-text-label-in-windows-forms)*. – Peter Mortensen Jan 15 '17 at 17:38

2 Answers2

60

If you are trying to display & in button text, use &&. A single & is used for keyboard shortcuts, and a double ampersand will escape that.

The article Escape ampersand (&) character in C# mentions that you can leave the caption unaltered with single & and just set UseMnemonic property of the button to false.

Martin Schneider
  • 14,263
  • 7
  • 55
  • 58
Bala R
  • 107,317
  • 23
  • 199
  • 210
  • "Gets or sets a value indicating whether the control interprets an ampersand character (&) in the control's Text property to be an access key prefix character." This property also exists for labels. – PeterCo Oct 30 '14 at 09:52
  • Is there a way to set a groupbox, for example, to UseMnemonic = false? They don't seem to have that property. I just hate how hacky it feels to have those shortcuts lying around everywhere – Ben Philipp Jan 26 '17 at 08:34
  • On some others controls like **TabPage** or **TrayIcon** you need to triple escape the amperstand (`&`) character using `&&&` – onirix May 05 '23 at 08:58
6

Try double & (&&). It works with VBA code.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rashmi
  • 61
  • 1
  • 1
  • 1
    VBA is not VB.net, although in this case it's the same. The VBA question is [vba - How to put an ampersand in a header/footer in Excel? - Stack Overflow](https://stackoverflow.com/questions/23129359/how-to-put-an-ampersand-in-a-header-footer-in-excel) – user202729 Aug 17 '21 at 13:19