TextSelection 接口
更新:2007 年 11 月
提供对基于视图的编辑操作和选定文本的访问。
命名空间: EnvDTE
程序集: EnvDTE(在 EnvDTE.dll 中)
语法
声明
<GuidAttribute("1FA0E135-399A-4D2C-A4FE-D21E2480F921")> _
Public Interface TextSelection
用法
Dim instance As TextSelection
[GuidAttribute("1FA0E135-399A-4D2C-A4FE-D21E2480F921")]
public interface TextSelection
[GuidAttribute(L"1FA0E135-399A-4D2C-A4FE-D21E2480F921")]
public interface class TextSelection
public interface TextSelection
备注
TextSelection 对象的属性和方法直接反映了 Visual Studio 集成开发环境 (IDE) 中的编辑器命令。像环境一样,文本选定操作受编辑器全局状态的影响,比如编辑器是处于覆盖模式还是处于虚拟空白模式。
如果影响了只读块中包含的任何字符,或者文本文档本身是只读的,则任何试图修改该文本文档的操作都将失败。
如果关联文档为 HTML 文档,则 TextSelection 对象的某些属性和方法可能会失败。可能的失败原因是:显示 HTML 文档的窗口不在源视图内,或文本文档背后的数据为锁定状态。
示例
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