在 Windows 窗体中的文本标签中输入“ &”符号?

如何在 C # (Windows 窗体)中向 Label中输入特殊字符?

如果您尝试在标签中写入“ &”,那么您将得到一个下划线。

那么 C # 等价于“ &”是什么呢? (“ &”显然不起作用)。

86938 次浏览

Two ways:

  • Escape it with another ampersand (&&).

  • Set UseMnemonic for that label to false. This causes all ampersands within the text to be taken literally so you don't need to double any of them. You'll lose the underlining and access key features though.

    You can set the value either in the designer, or in code:

    myLabel.UseMnemonic = false;
    myLabel.Text = "Text&Text";
    

You can escape & by adding it two times, to try &&.

Add another ampersand in front of it, so: &&

Or have a look at the following: Label.UseMnemonic (MSDN documentation)

I don't know how to use '&' in the designer, but in the code you can use '&&' for showing one '&'

Try this:

((char)0x26).ToString()