共用方式為


TextSelection.WordRight 方法

將選取文字向右移動指定的文字數。

命名空間:  EnvDTE
組件:  EnvDTE (在 EnvDTE.dll 中)

語法

'宣告
Sub WordRight ( _
    Extend As Boolean, _
    Count As Integer _
)
void WordRight(
    bool Extend,
    int Count
)
void WordRight(
    [InAttribute] bool Extend, 
    [InAttribute] int Count
)
abstract WordRight : 
        Extend:bool * 
        Count:int -> unit 
function WordRight(
    Extend : boolean, 
    Count : int
)

參數

  • Extend
    型別:System.Boolean
    選擇項。判斷移動的文字是否折疊。預設值為 false。
  • Count
    型別:System.Int32
    選擇項。代表要向右移動的文字數。預設值為 1。

備註

如果 Extend 為 true,則選取文字的作用端點會向右移動 Count 個文字。 否則,選取文字將會被摺疊並且置於作用終點右邊 Count 所指定文字數的位置。 如果還沒有移動到 Count 指定的文字數就碰到了文件的結尾,則位置就會保持在文件的結尾。

如果 Count 的值是負數,則 WordRight 的執行方式會與 WordLeft 相同。

文字文件的作用中語言管理員會定義「文字」(Word) 的涵義。

範例

Sub WordRightExample()
    ' Before running this example, open a text document.
    Dim objSel As TextSelection = DTE.ActiveDocument.Selection
    If objSel.IsEmpty Then
        ' If there is no text selected, swap the words before and after 
        ' the insertion point. We begin by selecting the word before 
        ' the insertion point.
        objSel.WordLeft(True)
        If Not objSel.IsEmpty Then
            ' We can continue only if the selection was not already at 
            ' the beginning of the document.
            Dim strBefore As String = objSel.Text

            ' The text is saved in strBefore; now delete it and move 
            ' past the following word.
            objSel.Delete()
            objSel.WordRight(True)
            If objSel.Text.StartsWith(" ") Or objSel.Text.StartsWith(Microsoft.VisualBasic.ControlChars.Tab) Then
                ' The previous call to WordRight may have skipped some 
                ' white space instead of an actual word. In that case, 
                ' we should call it again.
                objSel.WordRight(True)
            End If

            ' Insert the new text at the end of the selection.
            objSel.Insert(strBefore, vsInsertFlags.vsInsertFlagsInsertAtEnd)
        End If
    Else
        ' If some text is selected, replace the following word with the 
        ' selected text.
        Dim strSelected As String = objSel.Text

        objSel.MoveToPoint(objSel.BottomPoint)
        objSel.WordRight(True)
        If objSel.Text.StartsWith(" ") Or objSel.Text.StartsWith(Microsoft.VisualBasic.ControlChars.Tab) Then
            ' The previous call to WordRight may have skipped some 
            ' white space instead of an actual word. In that case, we 
            ' should call it again.
            objSel.WordRight(True)
        End If

        ' Insert the text, overwriting the existing text and leaving 
        ' the selection containing the inserted text.
        objSel.Insert(strSelected, vsInsertFlags.vsInsertFlagsContainNewText)
    End If
End Sub

.NET Framework 安全性

請參閱

參考

TextSelection 介面

EnvDTE 命名空間