TextPatternRange.CompareEndpoints Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Zwraca wartość wskazującą Int32 , czy dwa zakresy tekstu mają identyczne punkty końcowe.
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
Parametry
- endpoint
- TextPatternRangeEndpoint
- targetRange
- TextPatternRange
Zakres docelowy do porównania.
- targetEndpoint
- TextPatternRangeEndpoint
Zwraca
Zwraca wartość ujemną, jeśli punkt końcowy obiektu wywołującego występuje wcześniej w tekście niż docelowy punkt końcowy.
Zwraca zero, jeśli punkt końcowy obiektu wywołującego znajduje się w tej samej lokalizacji co docelowy punkt końcowy.
Zwraca wartość dodatnią, jeśli punkt końcowy obiektu wywołującego występuje później w tekście niż docelowy punkt końcowy.
Wyjątki
Jeśli zakres jest odwołaniem o wartości null (Nothing
w Visual Basic).
Jeśli zakres pochodzi z innego kontenera.
Przykłady
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
Uwagi
Porównując początkowe i końcowe punkty końcowe tego samego zakresu tekstu, można określić, czy zakres tekstu jest zdegenerowany, czy też punkty końcowe znajdują się w kolejności logicznego przepływu tekstu.