TextRange 接口

更新:2007 年 11 月

表示文本文档中单个连续的文本部分。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)

语法

声明
<GuidAttribute("72767524-E3B3-43D0-BB46-BBE1D556A9FF")> _
Public Interface TextRange
用法
Dim instance As TextRange
[GuidAttribute("72767524-E3B3-43D0-BB46-BBE1D556A9FF")]
public interface TextRange
[GuidAttribute(L"72767524-E3B3-43D0-BB46-BBE1D556A9FF")]
public interface class TextRange
public interface TextRange

备注

文本部分由一对 EditPoint 封闭。

如果有正则表达式,并且该表达式包含带标记的子表达式时,使用 TextRange 对象。返回范围的集合,每个范围对应一个匹配的子表达式,这些范围的属性是只读的。

对于常规文本操作,由于 TextSelection 对象与屏幕上的可见选定内容直接相关,建议您改用 TextSelectionEditPoint 之类的对象。选定内容区域更改时,对象的坐标也会更改,反之亦然。因此,文本选定内容不能用于表示文本的任意范围而不中断该文本选定内容。

示例

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 ("*/");
    }
}

另请参见

参考

TextRange 成员

EnvDTE 命名空间