共用方式為


TextBox.SelectionStart Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the starting position of the text selected in the text box.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property SelectionStart As Integer
public int SelectionStart { get; set; }
<TextBox SelectionStart="int"/>

Property Value

Type: System.Int32
The starting position of the current selection.

Exceptions

Exception Condition
ArgumentOutOfRangeException

The value is less than 0.

Remarks

If there is no selection, the SelectionStart value gets or sets the location of the cursor.

Setting this value changes the starting position of the selection box and raises a SelectionChanged event. The SelectionLength remains the same.

Examples

The following code example shows how you can use the SelectionStart property.

Private Sub SelectionStart()
    MyTB1.[Select](3, 2)

    'The starting position of the cursor is set to the fifth position. Note that the 
    'SelectionLength remains the same when the text is selected. 
    MyTB1.SelectionStart = 5
End Sub
private void SelectionStart()
{
    MyTB1.Select(3, 2);

    //The starting position of the cursor is set to the fifth position. Note that the 
    //SelectionLength remains the same when the text is selected.
    MyTB1.SelectionStart = 5;
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.