Export (0) Print
Expand All

TextSelection.MoveToLineAndOffset Method

Moves the active point to the given position.

Namespace: EnvDTE
Assembly: EnvDTE (in envdte.dll)

void MoveToLineAndOffset (
	[InAttribute] int Line,
	[InAttribute] int Offset,
	[OptionalAttribute] [InAttribute] bool Extend
void MoveToLineAndOffset (
	/** @attribute InAttribute() */ int Line, 
	/** @attribute InAttribute() */ int Offset, 
	/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ boolean Extend
function MoveToLineAndOffset (
	Line : int, 
	Offset : int, 
	Extend : boolean



Required. The line number to move to, beginning at one. Line may also be one of the constants from vsGoToLineOptions.


Required. The character index position in the line, starting at one.


Optional. Default = false. A Boolean value to extend the current selection. If Extend is true, then the active end of the selection moves to the location, while the anchor end remains where it is. Otherwise, both ends are moved to the specified location. This argument applies only to the TextSelection object.

If the value of Offset is beyond the last character of the line, the document moves to the end of the line.

Sub MoveToLineAndOffsetExample()
    ' Before running this example, open a text document.
    Dim objSel As TextSelection = DTE.ActiveDocument.Selection

    ' Move to the beginning of the document so we can iterate over the 
    ' whole thing.
    While objSel.FindPattern("#if _DEBUG")
        ' If we found the beginning of a debug-only section, save the 
        ' position.
        Dim lStartLine As Long = objSel.TopPoint.Line
        Dim lStartColumn As Long = objSel.TopPoint.LineCharOffset

        ' Look for the end.
        If objSel.FindPattern("#endif") Then
            ' Select the entire section and outline it.
            objSel.MoveToLineAndOffset(lStartLine, lStartColumn, True)
        End If
    End While
End Sub

Community Additions

© 2014 Microsoft