【发布时间】:2011-05-06 11:44:19
【问题描述】:
我有一个具有初始值的文本框(多行),现在当用户尝试将值附加到它时,他应该无法修改初始值。有没有可能?
【问题讨论】:
我有一个具有初始值的文本框(多行),现在当用户尝试将值附加到它时,他应该无法修改初始值。有没有可能?
【问题讨论】:
因此,如果您希望用户能够添加但不能删除该文本的框中有“lorem ipsum”?如果是这样,那么使用 RichTextBox 您可以通过选择的.SelectionProtected 属性来执行此操作,该属性会将区域标记为有效地只读。
rtBox.Select(0, (rtBox.Text = "I am fixed content").Length);
rtBox.SelectionProtected = true;
rtBox.AppendText(Environment.NewLine);
【讨论】:
另一种选择是使用蒙版文本框。这样,您可以根据需要拥有多个保护区。
例如,您可以将掩码设置为:
"This c\annot be ch\anged. But this c\an\: CCCCCCCCCC"
会显示为:
"This cannot be changed. But this can: __________"
输入与您希望用户能够输入的字符一样多的“C”。如果您愿意,也可以将提示字符更改为空格而不是“_”。
为了方便……
这里是屏蔽字符的列表和说明
(取自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 中显示为自身。文字在运行时始终占据掩码中的静态位置,用户无法移动或删除。
【讨论】:
您可以使用 RichTextBox SelectionProtected 属性。
【讨论】: