Export (0) Print
Expand All

TextSelection Interface

Provides access to view-based editing operations and selected text.

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

[GuidAttribute("1FA0E135-399A-4D2C-A4FE-D21E2480F921")]
public interface TextSelection

The TextSelection type exposes the following members.

  NameDescription
Public propertyActivePointGets the current endpoint of the selection.
Public propertyAnchorColumnInfrastructure. Microsoft Internal Use Only.
Public propertyAnchorPointGets the origin point of the selection.
Public propertyBottomLineInfrastructure. Microsoft Internal Use Only.
Public propertyBottomPointGets the point at the end of the selection.
Public propertyCurrentColumnInfrastructure. Microsoft Internal Use Only.
Public propertyCurrentLineInfrastructure. Microsoft Internal Use Only.
Public propertyDTEGets the top-level extensibility object.
Public propertyIsActiveEndGreaterGets whether the active point is equal to the bottom point.
Public propertyIsEmptyGets whether the anchor point is equal to the active point.
Public propertyModeSets or gets a value determining whether dragging the mouse selects in stream or block mode.
Public propertyParentGets the immediate parent object of a TextSelection object.
Public propertyTextSets or gets the text selection.
Public propertyTextPaneGets the text pane that contains the text selection.
Public propertyTextRangesGets a TextRanges collection with one TextRange object for each line or partial line in the selection.
Public propertyTopLineInfrastructure. Microsoft Internal Use Only.
Public propertyTopPointGets the top end of the selection.
Top

  NameDescription
Public methodBackspaceInfrastructure. Microsoft Internal Use Only.
Public methodCancelInfrastructure. Microsoft Internal Use Only.
Public methodChangeCaseChanges the case of the text selection.
Public methodCharLeftMoves the object the specified number of characters to the left.
Public methodCharRightMoves the object the specified number of characters to the right.
Public methodClearBookmarkClears any unnamed bookmarks in the current text buffer line.
Public methodCollapseCollapses the text selection to the active point.
Public methodCopyCopies the text selection to the clipboard.
Public methodCutCopies the text selection to the clipboard and deletes it from its original location.
Public methodDeleteDeletes the text selection.
Public methodDeleteLeftDeletes a specified number of characters to the left of the active point.
Public methodDeleteWhitespaceDeletes the empty characters (white space) horizontally or vertically around the current location in the text buffer.
Public methodDestructiveInsertInserts text, overwriting the existing text.
Public methodEndOfDocumentMoves the object to the end of the document.
Public methodEndOfLineMoves the object to the end of the current line.
Public methodFindPatternSearches for the given pattern from the active point to the end of the document.
Public methodFindTextSearches for the given text from the active point to the end of the document.
Public methodGotoLineMoves to the beginning of the indicated line and selects the line if requested.
Public methodIndentIndents the selected lines by the given number of indentation levels.
Public methodInsertInserts the given string at the current insertion point.
Public methodInsertFromFileInserts the contents of the specified file at the current location in the buffer.
Public methodLineDownMoves the insertion point of the text selection down the specified number of lines.
Public methodLineUpMoves the insertion point of the text selection up the specified number of lines.
Public methodMoveToInfrastructure. Microsoft Internal Use Only.
Public methodMoveToAbsoluteOffsetMoves the active point to the given 1-based absolute character offset.
Public methodMoveToDisplayColumnMoves the active point to the indicated display column.
Public methodMoveToLineAndOffsetMoves the active point to the given position.
Public methodMoveToPointMoves the active point to the given position.
Public methodNewLineInserts a line break character at the active point.
Public methodNextBookmarkMoves to the location of the next bookmark in the document.
Public methodOutlineSectionCreates an outlining section based on the current selection.
Public methodPadToColumnFills the current line in the buffer with empty characters (white space) to the given column.
Public methodPageDownMoves the active point a specified number of pages down in the document, scrolling the view.
Public methodPageUpMoves the active point a specified number of pages up in the document, scrolling the view.
Public methodPasteInserts the clipboard contents at the current location.
Public methodPreviousBookmarkMoves the text selection to the location of the previous bookmark in the document.
Public methodReplacePatternReplaces matching text throughout an entire text document.
Public methodReplaceTextInfrastructure. Microsoft Internal Use Only.
Public methodSelectAllSelects the entire document.
Public methodSelectLineSelects the line containing the active point.
Public methodSetBookmarkSets an unnamed bookmark on the current line in the buffer.
Public methodSmartFormatFormats the selected lines of text based on the current language.
Public methodStartOfDocumentMoves the insertion point to the beginning of the document.
Public methodStartOfLineMoves the object to the beginning of the current line.
Public methodSwapAnchorExchanges the position of the active and the anchor points.
Public methodTabifyConverts spaces to tabs in the selection according to your tab settings.
Public methodUnindentRemoves indents from the text selection by the number of indentation levels given.
Public methodUntabifyConverts tabs to spaces in the selection according to the user's tab settings.
Public methodWordLeftMoves the text selection left the specified number of words.
Public methodWordRightMoves the text selection right the specified number of words.
Top

The properties and methods of the TextSelection object directly reflect editor commands in the Visual Studio integrated development environment (IDE). Like the environment, text selection operations are affected by the editor's global state, such as whether it is in overwrite mode or virtual white space mode.

Any operation attempting to modify a text document fails if it affects any characters contained in a read-only block, or if the text document itself is read-only.

Some of the TextSelection object's properties and methods may fail if the associated document is an HTML document. Possible causes of the failure are: the windows that display the HTML document are not in Source view or the data behind the text document is locked.

Sub TextSelectionExample()
   ' Before running this example, open a text document.
   Dim objSel As TextSelection = DTE.ActiveDocument.Selection
   Dim objActive As VirtualPoint = objSel.ActivePoint
   ' Collapse the selection to the beginning of the line.
   objSel.StartOfLine()
   ' objActive is "live", tied to the position of the actual selection, 
   ' so it will reflect the new position.
   Dim iCol As Long = objActive.DisplayColumn
   ' Move the selection to the end of the line.
   objSel.EndOfLine()

   MsgBox("The length of the insertion point line is " & (objActive.DisplayColumn - iCol) & " display characters.")
End Sub
Show:
© 2014 Microsoft