TextPatternRange.Select Method ()

 

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 Sub 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 Sub SetSelection(ByVal target As AutomationElement, ByVal s As String, ByVal backward As Boolean, ByVal ignorecase As Boolean)
    ' 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
    End If
    Dim currentSelection As TextPatternRange() = textpatternPattern.GetSelection()
    Dim selectedText As TextPatternRange = currentSelection(0).FindText(s, backward, ignorecase)
    selectedText.Select()
End Sub

.NET Framework
Available since 3.0
Return to top
Show: