TextBox.SelectionLength 属性

定义

获取或设置一个值,该值指示文本框中当前选择的字符数。Gets or sets a value indicating the number of characters in the current selection in the text box.

public:
 property int SelectionLength { int get(); void set(int value); };
public int SelectionLength { get; set; }
member this.SelectionLength : int with get, set
Public Property SelectionLength As Integer

属性值

文本框中当前选择的字符数。The number of characters in the current selection in the text box. 默认值为 0。The default is 0.

异常

SelectionLength 设置为一个负值。SelectionLength is set to a negative value.

注解

获取此属性将返回当前选定内容中的字符数。Getting this property returns the number of characters in the current selection. 设置此属性会将当前所选内容的长度调整为指定的值, 并保持选择范围的开头。Setting this property adjusts the length of the current selection to the specified value, keeping the beginning of the selection fixed.

通常, 当指定的选择长度导致所选内容在无效位置结束时 (例如, 在回车符和换行字符之间或标记内), 选择长度会自动调整, 以便使所选内容开始和结束于有效的位置。In general, when the specified selection length causes the selection to end in an invalid position (for example, between a carriage return and a new-line character, or inside a tag), the selection length automatically adjusts so that the resulting selection starts and ends in valid positions.

适用于

另请参阅