输入“&"符号转换为 Windows 窗体中的文本标签? [英] Enter "&" symbol into a text Label in Windows Forms?

查看:18
本文介绍了输入“&"符号转换为 Windows 窗体中的文本标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How would one enter special characters into a Label in C# (Windows Forms)?

如果你尝试写一个&"进入一个标签,你会得到一种下划线.

If you try to write a "&" into a label you'll get a sort of underscore instead..

那么&"在 C# 中的等价物是什么?(&"显然不起作用).

So what's the C# equivalent of "&"? ("&" obviously doesn't work).

推荐答案

两种方式:

  • 用另一个&符号(&&)转义它.

设置 UseMnemonic 将该标签设为 false.这会导致文本中的所有&符号都按字面意思表示,因此您无需将其中任何一个加倍.但是,您将丢失下划线和访问关键功能.

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";

这篇关于输入“&"符号转换为 Windows 窗体中的文本标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆