次の方法で共有


TextSelection.WordLeft メソッド

テキストの選択状態を単語の数を指定します。

名前空間:  EnvDTE
アセンブリ:  EnvDTE (EnvDTE.dll 内)

構文

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

パラメーター

  • Extend
    型 : Boolean

    省略可能。 移動したテキストの範囲選択を解除するかどうかを指定します。 既定値は、false です。

  • Count
    型 : Int32

    省略可能。 左に移動する単語数。 既定値は 1 です。

解説

Extend が Trueの場合、テキストの選択項目のアクティブ単語の終わりが実行 Count 左の数です。 それ以外の場合、テキストの選択が折りたたまれ、Count の一つの単語はアクティブな末尾から残されています。 Count の単語数よりも前にドキュメントの先頭が来た場合は、位置はそのままドキュメントの先頭になります。

Count が負の値の場合、WordLeft は WordRight メソッドと同様に動作します。

テキスト ドキュメントのアクティブな言語マネージャーは、"単語" の意味を定義します。

Sub WordLeftExample()
    ' 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 
        ' text selection.
        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 名前空間