TextRange 接口

定义

表示文本文档中的单个连续文本部分。Represents a single, contiguous section of text in a text document.

public interface class TextRange
public interface class TextRange
__interface TextRange
[System.Runtime.InteropServices.Guid("72767524-E3B3-43D0-BB46-BBE1D556A9FF")]
[System.Runtime.InteropServices.TypeLibType(4160)]
public interface TextRange
[<System.Runtime.InteropServices.Guid("72767524-E3B3-43D0-BB46-BBE1D556A9FF")>]
[<System.Runtime.InteropServices.TypeLibType(4160)>]
type TextRange = interface
Public Interface TextRange
属性

示例

Sub TextRangeExample(ByVal dte As EnvDTE.DTE)  
    Dim objTxtSel As TextSelection  
    Dim colRanges As TextRanges  
    Dim objRange As TextRange  
    Dim objEP As EditPoint  

    objTxtSel = dte.ActiveDocument.Selection  
    colRanges = objTxtSel.TextRanges  
    For Each objRange In colRanges  
        objRange.StartPoint.Insert("/*")  
        objRange.EndPoint.Insert("*/")  
    Next  
End Sub  
public void TextRangeExample(_DTE dte)  
{  
    TextSelection ts;  
    TextRanges trs;  

    ts = (TextSelection)dte.ActiveDocument.Selection;  
    trs = ts.TextRanges;  
    MessageBox.Show (trs.Count.ToString ());  
    foreach (TextRange tr in trs)  
    {  
        tr.StartPoint.Insert ("/*");  
        tr.EndPoint.Insert ("*/");  
    }  
}  

注解

文本部分由一对对象括起来 EditPointThe section of text is enclosed by a pair of EditPoint objects.

TextRange 使用带标记的子表达式的正则表达式时使用对象。TextRange objects are used when you have regular expressions with tagged subexpressions. 返回范围的集合,每个匹配的子表达式对应一个范围,其属性为只读。A collection of ranges is returned, one for each matched subexpression, and their properties are read-only.

对于常规文本操作,建议改为使用对象(如 TextSelectionEditPoint ),因为 TextSelection 对象直接与屏幕上可见的选择相关。For general text manipulation, it is recommended that you instead use objects such as TextSelection or EditPoint, because the TextSelection object relates directly to the selection visible on the screen. 选择区域发生变化时,对象的坐标会发生变化,反之亦然。When the selection area changes, the object's coordinates change, and vice-versa. 因此,在不中断文本选择的情况下,不能使用文本选择来表示任意范围的文本。As a result, a text selection cannot be used to represent an arbitrary range of text without disrupting that text selection.

属性

Collection

获取包含支持此属性的 TextRange 对象的集合。Gets the collection containing the TextRange object supporting this property.

DTE

获取顶级扩展性对象。Gets the top-level extensibility object.

EndPoint

获取一个 EditPoint ,它是范围末尾的位置。Gets an EditPoint that is the location of the end of the range.

StartPoint

获取 EditPoint 表示文本文档开头或窗格的第一个显示字符的对象。Gets the EditPoint object representing the beginning of the text document, or the first displayed character of the pane.

适用于