共用方式為


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

備註

隱藏和可見文字之間沒有任何差異。 使用者介面自動化用戶端可用來 IsHiddenAttribute 檢查文字可見度。

注意

使用 DocumentRange 來搜尋整份檔。

適用於

另請參閱