TextSelection.MoveToLineAndOffset(Int32, Int32, Boolean) 方法

定义

将活动点移动到给定位置。

void MoveToLineAndOffset(int Line, int Offset, bool Extend = false);
[System.Runtime.InteropServices.DispId(39)]
public void MoveToLineAndOffset (int Line, int Offset, bool Extend = false);
[<System.Runtime.InteropServices.DispId(39)>]
abstract member MoveToLineAndOffset : int * int * bool -> unit
Public Sub MoveToLineAndOffset (Line As Integer, Offset As Integer, Optional Extend As Boolean = false)

参数

Line
Int32

必需。 要移至的行号,从1开始。 Line 也可能是来自的常数之一 vsGoToLineOptions

Offset
Int32

必需。 该行中的字符索引位置,从 1 开始。

Extend
Boolean

可选。 默认值 = false。 扩展当前选定范围的布尔值。 如果 Extendtrue ,则选定内容的活动端会移到该位置,而定位端保留在该位置。 否则,两端都会移动到指定位置。 此参数仅适用于 TextSelection 对象。

属性

示例

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.  
    objSel.StartOfDocument()  
    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.SwapAnchor()  
            objSel.MoveToLineAndOffset(lStartLine, lStartColumn, True)  
            objSel.OutlineSection()  
            objSel.LineDown()  
        End If  
    End While  
End Sub  

注解

如果的值 Offset 超出行的最后一个字符,则文档将移动到行的末尾。

适用于