Udostępnij za pośrednictwem


TextRange Interface

Definition

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")]
public interface TextRange
[<System.Runtime.InteropServices.Guid("72767524-E3B3-43D0-BB46-BBE1D556A9FF")>]
[<System.Runtime.InteropServices.TypeLibType(4160)>]
type TextRange = interface
[<System.Runtime.InteropServices.Guid("72767524-E3B3-43D0-BB46-BBE1D556A9FF")>]
type TextRange = interface
Public Interface TextRange
Attributes

Examples

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

Remarks

The section of text is enclosed by a pair of EditPoint objects.

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.

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.

Properties

Collection

Gets the collection containing the TextRange object supporting this property.

DTE

Gets the top-level extensibility object.

EndPoint

Gets an EditPoint that is the location of the end of the range.

StartPoint

Gets the EditPoint object representing the beginning of the text document, or the first displayed character of the pane.

Applies to