TextPatternRange.FindText(String, Boolean, Boolean) Méthode

Définition

Retourne un sous-ensemble de la plage de texte qui contient le texte spécifié.

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

Paramètres

text
String

Chaîne de texte à rechercher.

backward
Boolean

true si la dernière plage de texte doit être retournée à la place de la première ; sinon, false.

ignoreCase
Boolean

true si la casse doit être ignorée ; sinon, false.

Retours

Plage de texte correspondant au texte spécifié ; sinon, null (Nothing en Visual Basic).

Exemples

 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

Remarques

Il n’y a pas de différenciation entre le texte masqué et le texte visible. Les clients UI Automation peuvent utiliser IsHiddenAttribute pour case activée la visibilité du texte.

Notes

Utilisez DocumentRange pour rechercher l’intégralité du document.

S’applique à

Voir aussi