我将向 Windows 窗体上的标签中输入一些字符串(我不常使用这些字符串)。字符串将类似于以下内容:
"The quick brown fox j___ed over the l__y hound"
我想在标签中显示字符串,但在缺少字母的位置恰好覆盖一个 TextBox。
将有 300 多个字符串,我正在寻找最简单、最优雅的方法。
如何为每个字符串准确地重新定位文本框?
编辑: MaskTextBox 无法工作,因为我需要多行支持。
最佳答案
一种选择是使用蒙版文本框。
在您的示例中,您会将掩码设置为:
"The quick brown fox jLLLed over the l\azy hound"
这将显示为:
"The quick brown fox j___ed over the lazy hound"
并且只允许在空格中输入 3 个字符(a-z 和 A-Z)。 掩码可以通过代码轻松更改。
编辑: 为了方便...
这是屏蔽字符的列表和描述
(取自 http://www.c-sharpcorner.com/uploadfile/mahesh/maskedtextbox-in-C-Sharp/ )。
0 - Digit, required. Value between 0 and 9.
9 - Digit or space, optional.
# - Digit or space, optional. If this position is blank in the mask, it will be rendered as a space in the Text property.
L - Letter, required. Restricts input to the ASCII letters a-z and A-Z.
? - Letter, optional. Restricts input to the ASCII letters a-z and A-Z.
& - Character, required.
C - Character, optional. Any non-control character.
A - Alphanumeric, required.
a - Alphanumeric, optional.
. - Decimal placeholder.
, - Thousands placeholder.
: - Time separator.
/ - Date separator.
$ - Currency symbol.
< - Shift down. Converts all characters that follow to lowercase.
> - Shift up. Converts all characters that follow to uppercase.
| - Disable a previous shift up or shift down.
\ - Escape. Escapes a mask character, turning it into a literal. "\\" is the escape sequence for a backslash.
所有其他字符 - 文字。所有非掩码元素都将在 MaskedTextBox 中显示为它们自己。文字在运行时始终占据掩码中的静态位置,用户无法移动或删除。
关于c# - 我如何(优雅地)将文本框转置到字符串特定部分的标签上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48401824/