共用方式為


TextPatternRange.CompareEndpoints 方法

定義

傳回 Int32,表示兩個文字範圍是否有相同的端點。

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

參數

endpoint
TextPatternRangeEndpoint

呼叫端的 StartEnd 端點。

targetRange
TextPatternRange

比較的目標範圍。

targetEndpoint
TextPatternRangeEndpoint

目標的 StartEnd 端點。

傳回

Int32

如果呼叫端的端點在文字中比目標端點更早出現,則傳回負值。

如果呼叫端的端點與目標端點在相同位置,則傳回零。

如果呼叫端的端點在文字中比目標端點更晚出現,則傳回正值。

例外狀況

如果範圍是 Null 參考 (在 Visual Basic 中為 Nothing)。

如果範圍來自另一個容器。

範例

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

備註

藉由比較相同文字範圍的開始和結束端點,您可以識別文字範圍是否變質,或端點是否依邏輯文字流程的順序。

適用於

另請參閱