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

如果调用方的端点在文本中比目标端点先出现,则返回一个负值。

如果调用方的端点与目标端点处于同一位置,则返回零。

如果调用方的端点在文本中比目标端点后出现,则返回一个正值。

例外

如果范围是空引用(在 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

注解

通过比较同一文本范围的起始终结点和结束终结点,可以确定文本范围是否退化,或者终结点是否按逻辑文本流顺序排列。

适用于

另请参阅