TextPatternRange.MoveEndpointByRange Method (TextPatternRangeEndpoint, TextPatternRange, TextPatternRangeEndpoint)

 

Moves one endpoint of a text range to the specified endpoint of a second text range.

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

public void MoveEndpointByRange(
	TextPatternRangeEndpoint endpoint,
	TextPatternRange targetRange,
	TextPatternRangeEndpoint targetEndpoint
)

Parameters

endpoint
Type: System.Windows.Automation.Text.TextPatternRangeEndpoint

The endpoint to move.

targetRange
Type: System.Windows.Automation.Text.TextPatternRange

Another range from the same text provider.

targetEndpoint
Type: System.Windows.Automation.Text.TextPatternRangeEndpoint

An endpoint on the other range.

If the endpoint being moved crosses the other endpoint of the same text range then that other endpoint is moved also, resulting in a degenerate range and ensuring the correct ordering of the endpoints (that is, Start is always less than or equal to End).

 private void MoveEndpointByRangeFromSelection(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;
    }
    TextPatternRange[] currentSelection = textpatternPattern.GetSelection();
    TextPatternRange[] currentVisibleRanges = textpatternPattern.GetVisibleRanges();

    currentSelection[0].MoveEndpointByRange(
        TextPatternRangeEndpoint.Start,
        currentVisibleRanges[0], 
        TextPatternRangeEndpoint.Start);
}

.NET Framework
Available since 3.0
Return to top
Show: