2011-05-06 51 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中出現。文字在運行時總是在掩碼中佔據一個靜態位置,並且不能被用戶移動或刪除。