c# - 我如何(优雅地)将文本框转置到字符串特定部分的标签上?

标签 c# .net vb.net winforms

我将向 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/

相关文章:

c# - 使用 html 助手时没有发布值

c# - 如何在 ASP .NET MVC 中将对象列表与用户(帐户)相关联

.net - Interop:在部署 VB6 + .NET 组件时,是否需要 .TLB?

vb.net - Excel Interop 中的联合范围

c# - 在 Identity Asp.net core 3 MVC 中创建服务 IUserStore 时出错

c# - C++/C# 解决方案中不可用的任何 CPU

c# - 表单 DataGridView 缺少 OnRowDataBound?

c# - CreateMap 抛出异常

asp.net - 找不到 ID 为 'xxx' 的 UpdatePanel 。如果它是动态更新的,那么它必须位于另一个 UpdatePanel 内

c# - 通过来自同一对象实例(或基础)的反射调用私有(private)/ protected 方法