2011-05-06 32 views

回答

0

你可以使用的RichTextBox SelectionProtected属性。

3

因此,如果你想让用户能够添加但不删除该文本的框中有“lorem ipsum”?如果是这样,然后RichTextBox你可以通过选择的.SelectionProtected属性来做到这一点,它将标记一个区域为有效地只读。

rtBox.Select(0, (rtBox.Text = "I am fixed content").Length); 
rtBox.SelectionProtected = true; 
rtBox.AppendText(Environment.NewLine); 
0

另一种选择是使用屏蔽文本框。这样,如果您愿意,您可以拥有多个保护区。

例如,您将设置面膜:这将显示为

"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中出现。文字在运行时总是在掩码中占据一个静态位置,并且不能被用户移动或删除。