|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
Assembly: EnvDTE (in envdte.dll)
/** @attribute GuidAttribute("1FA0E135-399A-4D2C-A4FE-D21E2480F921") */ public interface TextSelection
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