This documentation is archived and is not being maintained.

TextSelection.MoveToLineAndOffset Method

Moves the active point to the given position.

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

void MoveToLineAndOffset(
	int Line,
	int Offset,
	bool Extend


Type: System.Int32

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

Type: System.Int32

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

Type: System.Boolean

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