次の方法で共有


TextRange インターフェイス

テキスト ドキュメント内のテキストの単一の、連続するセクションを表します。

名前空間:  EnvDTE
アセンブリ:  EnvDTE (EnvDTE.dll 内)

構文

'宣言
<GuidAttribute("72767524-E3B3-43D0-BB46-BBE1D556A9FF")> _
Public Interface TextRange
[GuidAttribute("72767524-E3B3-43D0-BB46-BBE1D556A9FF")]
public interface TextRange
[GuidAttribute(L"72767524-E3B3-43D0-BB46-BBE1D556A9FF")]
public interface class TextRange
[<GuidAttribute("72767524-E3B3-43D0-BB46-BBE1D556A9FF")>]
type TextRange =  interface end
public interface TextRange

TextRange 型で公開されるメンバーは以下のとおりです。

プロパティ

  名前 説明
パブリック プロパティ Collection このプロパティをサポートしている TextRange オブジェクトを含んでいるコレクションを取得します。
パブリック プロパティ DTE トップレベルの機能拡張オブジェクトを取得します。
パブリック プロパティ EndPoint 範囲の終了位置である EditPoint を取得します。
パブリック プロパティ StartPoint テキスト ドキュメントの先頭、またはペインで最初に表示される文字を表す EditPoint オブジェクトを取得します。

このページのトップへ

解説

テキストのセクションは、EditPoint オブジェクトのペアで囲まれます。

TextRange オブジェクトは、タグ付き部分式を持つ正規表現がある場合に使用されます。 一致する各部分式につき 1 つの範囲のコレクションが返されます。コレクションのプロパティは読み取り専用です。

一般的なテキスト操作の場合には、代わりに TextSelection または EditPoint などのオブジェクトを使用することをお勧めします。これは、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 ("*/");
    }
}

参照

関連項目

EnvDTE 名前空間