TextPatternRange.Select Method ()

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Highlights text in the text control corresponding to the text range Start and End endpoints.

Namespace:   System.Windows.Automation.Text
Assembly:  UIAutomationClient (in UIAutomationClient.dll)

public void Select()

Exception Condition
InvalidOperationException

Occurs when text selection is not supported by the text control.

If a degenerate text range is provided, the text insertion point will move to the Start endpoint of the text range.

private void SetSelection(AutomationElement target, String s, Boolean backward, Boolean ignorecase)
{
    // 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;
    }
    TextPatternRange[] currentSelection = textpatternPattern.GetSelection();

    TextPatternRange tprText = currentSelection[0].FindText(s, backward, ignorecase);
    tprText.Select();
}

.NET Framework
Available since 3.0
Return to top
Show: