TextPatternRange.Compare(TextPatternRange) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
public:
bool Compare(System::Windows::Automation::Text::TextPatternRange ^ range);
public bool Compare (System.Windows.Automation.Text.TextPatternRange range);
member this.Compare : System.Windows.Automation.Text.TextPatternRange -> bool
Public Function Compare (range As TextPatternRange) As Boolean
パラメーター
- range
- TextPatternRange
比較するテキスト範囲。
戻り値
両方のテキスト範囲が同じである場合は true
。それ以外の場合は false
。
例外
比較している範囲が同じテキスト プロバイダーからのものではない。
例
private Boolean CompareRanges(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 false;
}
TextPatternRange[] currentSelection = textpatternPattern.GetSelection();
TextPatternRange[] currentVisibleRanges = textpatternPattern.GetVisibleRanges();
return currentSelection[0].Compare(currentVisibleRanges[0]);
}
Private Function CompareRanges(ByVal target As AutomationElement) As Boolean
' 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 currentVisibleRange As TextPatternRange() = textpatternPattern.GetVisibleRanges()
Return currentSelection(0).Compare(currentVisibleRange(0))
End Function