TextPatternRange.FindText(String, Boolean, Boolean) メソッド

定義

指定したテキストを含むテキスト範囲のサブセットを返します。

public:
 System::Windows::Automation::Text::TextPatternRange ^ FindText(System::String ^ text, bool backward, bool ignoreCase);
public System.Windows.Automation.Text.TextPatternRange FindText(string text, bool backward, bool ignoreCase);
member this.FindText : string * bool * bool -> System.Windows.Automation.Text.TextPatternRange
Public Function FindText (text As String, backward As Boolean, ignoreCase As Boolean) As TextPatternRange

パラメーター

text
String

検索するテキスト文字列。

backward
Boolean

true 最初のテキスト範囲ではなく、最後に発生したテキスト範囲を返す必要がある場合。それ以外の場合は false

ignoreCase
Boolean

true 大文字と小文字を区別する必要がある場合は無視します。それ以外の場合は false

返品

指定したテキストと一致するテキスト範囲。それ以外の場合は null (Visual Basic では Nothing)。

 private TextPatternRange TextFromSelection(AutomationElement target)
{
    // Specify the control type we're looking for, in this case 'Document'
    PropertyCondition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document);

    // target --> The root AutomationElement.
    AutomationElement textProvider = target.FindFirst(TreeScope.Descendants, cond);

    TextPattern textpatternPattern = textProvider.GetCurrentPattern(TextPattern.Pattern) as TextPattern;

    if (textpatternPattern == null)
    {
        Console.WriteLine("Root element does not contain a descendant that supports TextPattern.");
        return null;
    }
    TextPatternRange[] tprSelection = textpatternPattern.GetSelection();
    // Find 'text' in selection range
    return tprSelection[0].FindText("text", false, true);
}
Private Function TextFromSelection(ByVal target As AutomationElement) As TextPatternRange
    ' Specify the control type we're looking for, in this case 'Document'
    Dim cond As PropertyCondition = New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document)

    ' target --> The root AutomationElement.
    Dim textProvider As AutomationElement = target.FindFirst(TreeScope.Descendants, cond)

    Dim textpatternPattern As TextPattern = CType(textProvider.GetCurrentPattern(TextPattern.Pattern), TextPattern)

    If (textpatternPattern Is Nothing) Then
        Console.WriteLine("Root element does not contain a descendant that supports TextPattern.")
        Return Nothing
    End If
    Dim currentSelection As TextPatternRange() = textpatternPattern.GetSelection()
    ' Find 'text' in selection range
    Return currentSelection(0).FindText("text", False, True)
End Function

注釈

非表示のテキストと表示されるテキストは区別されません。 UI オートメーションクライアントは、IsHiddenAttribute を使用してテキストの可視性を確認できます。

Note

DocumentRangeを使用してドキュメント全体を検索します。

適用対象

こちらもご覧ください