Поделиться через


TextSelection.Insert Method

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

Inserts or replaces the content at the current selection as a TextElement.

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

Syntax

'Declaration
Public Sub Insert ( _
    element As TextElement _
)
public void Insert(
    TextElement element
)

Parameters

Remarks

This method inserts the content at the current position if there no selection or an empty selection. If there is a selection, this method replaces the current selection with the content.

Examples

The following example uses the Insert method to insert a Run element into the RichTextBox.

Run this sample

<RichTextBox Name="MyRTB1" Width="150" Height="30" Margin="5"/>
<Button Click="MyButton1_Click" Content="Insert Text" Height="23" Name="MyButton1" Width="75" />
'Change the current selection. 
Private Sub BoldInsertedText()
    Dim MyRun As New Run()
    MyRun.Text = "New inserted text"

    MyRTB1.Selection.Insert(MyRun)
End Sub

Private Sub MyButton1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    BoldInsertedText()
End Sub
//Change the current selection.   
private void BoldInsertedText()
{
    Run MyRun = new Run();
    MyRun.Text = "New inserted text";
    MyRTB1.Selection.Insert(MyRun);

}

private void MyButton1_Click(object sender, RoutedEventArgs e)
{
    BoldInsertedText();
}

Version Information

Silverlight

Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

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