TextPatternRange.Select Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
public:
void Select();
public void Select ();
member this.Select : unit -> unit
Public Sub Select ()
Exceptions
Occurs when text selection is not supported by the text control.
Examples
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();
}
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
Remarks
If a degenerate text range is provided, the text insertion point will move to the Start endpoint of the text range.
Applies to
See also
Samarbeid med oss på GitHub
Du finner kilden for dette innholdet på GitHub. Der du også kan opprette og se gjennom problemer og pull-forespørsler. Hvis du vil ha mer informasjon, kan du se vår bidragsyterveiledning.