Partilhar via


TextPatternRange.CompareEndpoints Método

Definição

Retorna um Int32 que indica se dois intervalos de texto têm pontos de extremidade idênticos.

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

Parâmetros

endpoint
TextPatternRangeEndpoint

O ponto de extremidade Start ou End do chamador.

targetRange
TextPatternRange

O intervalo de destino para comparação.

targetEndpoint
TextPatternRangeEndpoint

O ponto de extremidade Start ou End do destino.

Retornos

Int32

Retorna um valor negativo se o ponto de extremidade do chamador ocorre antes no texto do que o ponto de extremidade de destino.

Retorna zero se o ponto de extremidade do chamador está no mesmo local que o ponto de extremidade de destino.

Retorna um valor positivo se o ponto de extremidade do chamador ocorre depois no texto do que o ponto de extremidade de destino.

Exceções

Se o intervalo é uma referência nula (Nothing no Visual Basic).

Se o intervalo for de outro contêiner.

Exemplos

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

Comentários

Comparando os pontos de extremidade iniciais e finais do mesmo intervalo de texto, você pode identificar se um intervalo de texto é degenerado ou se os pontos de extremidade estão na ordem do fluxo de texto lógico.

Aplica-se a

Confira também