Represents either a selected (highlighted) text in the editor control, or the insertion point if nothing in the document is selected.
For a list of all members of this type, see Selection Members.
System.Object
Aspose.Editor.Desktop.Selection
[Visual Basic]
Public Class Selection
[C#]public class Selection
Remarks
Use the Selection property of the EditorControl class to return the current selection. You do not create instances of Selection directly.
The Selection object has various methods and properties that allow you to expand, collapse or otherwise change the current selection: Move, EndKey, HomeKey and so on.
The Selection object has various methods and properties with which you can edit selected text: TypeText, TypeParagraph, Bold, Italic and so on.
Use the Range property to obtain a range that represents the current selection. The Range object provides more methods and properties to programmatically edit and format the text.
Example
Shows how to cut, copy and paste fragments of a document.
[C#]
/// <summary>
/// This is a handler for the Edit | Cut menu.
/// </summary>
private void EditCut(object sender, System.EventArgs e)
{
Debug.Assert(editorControl.Document != null);
Debug.Assert(!editorControl.Selection.IsEmpty);
// Aspose.Editor has the Selection and Range objects that work and feel in many
// ways similar to Microsoft Word Automation.
editorControl.Selection.Range.Cut();
}
/// <summary>
/// This is a handle for the Edit | Copy menu.
/// </summary>
private void EditCopy(object sender, System.EventArgs e)
{
Debug.Assert(editorControl.Document != null);
Debug.Assert(!editorControl.Selection.IsEmpty);
editorControl.Selection.Range.Copy();
}
/// <summary>
/// This is a handle for the Edit | Paste menu.
/// </summary>
private void EditPaste(object sender, System.EventArgs e)
{
Debug.Assert(editorControl.Document != null);
Debug.Assert(editorControl.Document.CanPaste(Clipboard.GetDataObject()));
editorControl.Selection.Range.Paste();
// After the paste operation, the pasted range is selected.
// This line moves the cursor to the end of the selection.
editorControl.Selection.Range.Collapse(false);
}
[Visual Basic]
''' <summary>
''' This is a handler for the Edit | Cut menu.
''' </summary>
Private Sub EditCut(ByVal sender As Object, ByVal e As System.EventArgs)
Debug.Assert(Not editorControl.Document Is Nothing)
Debug.Assert((Not editorControl.Selection.IsEmpty))
' Aspose.Editor has the Selection and Range objects that work and feel in many
' ways similar to Microsoft Word Automation.
editorControl.Selection.Range.Cut()
End Sub
''' <summary>
''' This is a handle for the Edit | Copy menu.
''' </summary>
Private Sub EditCopy(ByVal sender As Object, ByVal e As System.EventArgs)
Debug.Assert(Not editorControl.Document Is Nothing)
Debug.Assert((Not editorControl.Selection.IsEmpty))
editorControl.Selection.Range.Copy()
End Sub
''' <summary>
''' This is a handle for the Edit | Paste menu.
''' </summary>
Private Sub EditPaste(ByVal sender As Object, ByVal e As System.EventArgs)
Debug.Assert(Not editorControl.Document Is Nothing)
Debug.Assert(editorControl.Document.CanPaste(Clipboard.GetDataObject()))
editorControl.Selection.Range.Paste()
' After the paste operation, the pasted range is selected.
' This line moves the cursor to the end of the selection.
editorControl.Selection.Range.Collapse(False)
End SubRequirements
Namespace: Aspose.Editor.Desktop
Assembly: Aspose.Editor.Desktop (in Aspose.Editor.Desktop.dll)
See Also
Selection Members | Aspose.Editor.Desktop Namespace | EditorControl | Range