TextPatternRange.CompareEndpoints(TextPatternRangeEndpoint, TextPatternRange, TextPatternRangeEndpoint) Metodo

Definizione

Restituisce un oggetto Int32 che indica se due intervalli di testo presentano endpoint identici.Returns an Int32 indicating whether two text ranges have identical endpoints.

public:
 int CompareEndpoints(System::Windows::Automation::Text::TextPatternRangeEndpoint endpoint, System::Windows::Automation::Text::TextPatternRange ^ targetRange, System::Windows::Automation::Text::TextPatternRangeEndpoint targetEndpoint);
public int CompareEndpoints (System.Windows.Automation.Text.TextPatternRangeEndpoint endpoint, System.Windows.Automation.Text.TextPatternRange targetRange, System.Windows.Automation.Text.TextPatternRangeEndpoint targetEndpoint);
member this.CompareEndpoints : System.Windows.Automation.Text.TextPatternRangeEndpoint * System.Windows.Automation.Text.TextPatternRange * System.Windows.Automation.Text.TextPatternRangeEndpoint -> int
Public Function CompareEndpoints (endpoint As TextPatternRangeEndpoint, targetRange As TextPatternRange, targetEndpoint As TextPatternRangeEndpoint) As Integer

Parametri

endpoint
TextPatternRangeEndpoint

Endpoint Start o End del chiamante.The Start or End endpoint of the caller.

targetRange
TextPatternRange

Intervallo di destinazione per il confronto.The target range for comparison.

targetEndpoint
TextPatternRangeEndpoint

Endpoint Start o End della destinazione.The Start or End endpoint of the target.

Restituisce

Int32

Restituisce un valore negativo se l'endpoint del chiamante si trova nel testo prima dell'endpoint di destinazione.Returns a negative value if the caller's endpoint occurs earlier in the text than the target endpoint.

Restituisce zero se l'endpoint del chiamante è nella stessa posizione dell'endpoint di destinazione.Returns zero if the caller's endpoint is at the same location as the target endpoint.

Restituisce un valore positivo se l'endpoint del chiamante si trova nel testo dopo l'endpoint di destinazione.Returns a positive value if the caller's endpoint occurs later in the text than the target endpoint.

Eccezioni

Se l'intervallo è un riferimento Null (Nothing in Visual Basic).If range is a null reference (Nothing in Visual Basic).

Se l'intervallo proviene da un altro contenitore.If range is from another container.

Esempio

private Int32 CompareRangeEndpoints(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 0;
    }
    TextPatternRange[] currentSelections = textpatternPattern.GetSelection();
    TextPatternRange[] currentVisibleRanges = textpatternPattern.GetVisibleRanges();
    return currentSelections[0].CompareEndpoints(
        TextPatternRangeEndpoint.Start, 
        currentVisibleRanges[0], 
        TextPatternRangeEndpoint.Start);
}
Private Function CompareRangeEndpoints(ByVal target As AutomationElement) As Integer
    ' 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()
    Dim currentVisibleRanges As TextPatternRange() = textpatternPattern.GetVisibleRanges()
    Return currentSelection(0).CompareEndpoints(TextPatternRangeEndpoint.Start, _
                                         currentVisibleRanges(0), _
                                         TextPatternRangeEndpoint.Start)
End Function

Commenti

Confrontando gli endpoint iniziale e finale dello stesso intervallo di testo è possibile identificare se un intervallo di testo è degenerato o se gli endpoint sono in ordine di flusso di testo logico.By comparing the starting and ending endpoints of the same text range you can identify if a text range is degenerate or if the endpoints are in the order of logical text flow.

Si applica a

Vedi anche