Table of Contents

Property Selection

Namespace
Alternet.Editor.Wpf
Assembly
Alternet.Editor.Wpf.v9.dll

Selection

Represents an object that implements ISelection interface. This object represents various properties and methods to manipulate text selection, such as copy, paste and drag selected text.

public ISelection Selection { get; }

Property Value

ISelection

Examples

Here is how to use a Selection in the C# code:

using System.Windows.Media;

public partial class MainWindow : Window
{
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        var textEditor = new Alternet.Editor.Wpf.TextEditor();
        textSource.LoadFile("myfile.txt");
        textEditor.Selection.Options |= SelectionOptions.DrawBorder;
        textEditor.SelectionBrush = new SolidColorBrush(Colors.LightBlue);
        textEditor.Selection.SelectionChanged += Selection_SelectionChanged;
    }

    private void Selection_SelectionChanged(object sender, EventArgs e)
    {
        System.Console.WriteLine(textEditor.Selection.SelectedText);
    }
}

Here is how to use a Selection in the Visual Basic code:

Imports System.Windows.Media
Partial Public Class MainWindow

    Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim textEditor = New Alternet.Editor.Wpf.TextEditor()
        textEditor.LoadFile("myfile.txt")
        textEditor.Selection.Options = textEditor.Selection.Options Or SelectionOptions.DrawBorder
        textEditor.SelectionBrush = New SolidColorBrush(Colors.LightBlue)
        AddHandler textEditor.Selection.SelectionChanged, New System.EventHandler(AddressOf Selection_SelectionChanged)
    End Sub

    Private Sub Selection_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
        System.Console.WriteLine(textEditor.Selection.SelectedText)
    End Sub
End Class

Remarks

Use ISelection property to control the appearance of selected text, such as background color, and programmatically select and manipulate blocks of the text within the TextEditor control.