对搜索模式中的每个带标记的子表达式都包含一个 TextRange 对象。 TextRanges 也用于查找选择框与每一行文本相交的位置。
命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)
语法
声明
<GuidAttribute("B6422E9C-9EFD-4F87-BDDC-C7FD8F2FD303")> _
Public Interface TextRanges _
    Inherits IEnumerable
[GuidAttribute("B6422E9C-9EFD-4F87-BDDC-C7FD8F2FD303")]
public interface TextRanges : IEnumerable
[GuidAttribute(L"B6422E9C-9EFD-4F87-BDDC-C7FD8F2FD303")]
public interface class TextRanges : IEnumerable
[<GuidAttribute("B6422E9C-9EFD-4F87-BDDC-C7FD8F2FD303")>]
type TextRanges =  
    interface
        interface IEnumerable
    end
public interface TextRanges extends IEnumerable
TextRanges 类型公开以下成员。
属性
| 名称 | 说明 | |
|---|---|---|
| .gif) | Count | 获取一个值,该值指示集合中对象的数目。 | 
| .gif) | DTE | 获取顶级扩展性对象。 | 
| .gif) | Parent | 获取 TextRanges 集合的直接父对象。 | 
页首
方法
| 名称 | 说明 | |
|---|---|---|
| .gif) | GetEnumerator() | 返回一个循环访问集合的枚举数。 (继承自 IEnumerable。) | 
| .gif) | GetEnumerator() | 获取集合中项的枚举。 | 
| .gif) | Item | 返回 TextRanges 集合中的一个 TextRange 对象。 | 
页首
备注
当搜索模式是具有带标记子表达式的正则表达式时,搜索操作返回 TextRanges 集合。 TextRanges 集合包含对应于每一个带标记子表达式的 TextRange 对象。
此外,如果需要确定选择框与每一行相交于何处,也可使用 TextRanges 从 TextSelection 对象获取选择框。
示例
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 ("*/");
    }
}