Partage via


TextPatternRange.CompareEndpoints Méthode

Définition

Retourne un élément Int32 qui indique si deux plages de texte ont des points de terminaison identiques.

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

Paramètres

endpoint
TextPatternRangeEndpoint

Point de terminaison Start ou End de l'appelant.

targetRange
TextPatternRange

Plage cible à comparer.

targetEndpoint
TextPatternRangeEndpoint

Point de terminaison Start ou End de la cible.

Retours

Int32

Retourne une valeur négative si le point de terminaison de l'appelant se situe dans le texte avant le point de terminaison cible.

Retourne zéro si le point de terminaison de l'appelant est au même emplacement que le point de terminaison cible.

Retourne une valeur positive si le point de terminaison de l'appelant se situe dans le texte après le point de terminaison cible.

Exceptions

S la plage est une référence null (Nothing en Visual Basic).

Si la plage est d'un autre conteneur.

Exemples

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

Remarques

En comparant les points de terminaison de début et de fin de la même plage de texte, vous pouvez identifier si une plage de texte est dégénérée ou si les points de terminaison se trouvent dans l’ordre du flux de texte logique.

S’applique à

Voir aussi