語言

Automation.Compare 方法

定義

比較指定的參數,以判斷它們是否指向相同的使用者介面(UI)元素。

多載

名稱 Description
Compare(Int32[], Int32[])

比較包含執行時識別碼(ID)的兩個整數陣列,以判斷其內容是否相同。

Compare(AutomationElement, AutomationElement)

比較兩個 使用者介面自動化 元素,若兩者指向同一 UI 元素,則回傳 true。

Compare(Int32[], Int32[])

比較包含執行時識別碼(ID)的兩個整數陣列,以判斷其內容是否相同。

public:
 static bool Compare(cli::array <int> ^ runtimeId1, cli::array <int> ^ runtimeId2);
public static bool Compare(int[] runtimeId1, int[] runtimeId2);
static member Compare : int[] * int[] -> bool
Public Shared Function Compare (runtimeId1 As Integer(), runtimeId2 As Integer()) As Boolean

參數

runtimeId1
Int32[]

這是第一個執行時的 ID 比較。

runtimeId2
Int32[]

第二個執行時 ID 要比較。

傳回

true 如果比較的執行時 ID 指向相同的使用者介面(UI)元素;否則 false。

範例

以下範例函式判斷執行時 ID 是否存在於執行時 ID 清單中。

private int RuntimeIdListed(int[] runtimeId, ArrayList runtimeIds)
{
    for (int x = 0; x < runtimeIds.Count; x++)
    {
        int[] listedId = (int[])runtimeIds[x];
        if (Automation.Compare(listedId, runtimeId))
        {
            return x;
        }
    }
    return -1;
}
Private Function RuntimeIdListed(ByVal runtimeId() As Integer, ByVal runtimeIds As ArrayList) As Integer 
    Dim x As Integer
    For x = 0 To runtimeIds.Count - 1
        Dim listedId As Integer() = CType(runtimeIds(x), Integer())
        If Automation.Compare(listedId, runtimeId) Then
            Return x
        End If
    Next x
    Return - 1

End Function 'RuntimeIdListed

備註

如果任一參數是空參考(Nothing in Visual Basic),Compare 會拋出 ArgumentNullException 例外。

另請參閱

適用於

Compare(AutomationElement, AutomationElement)

比較兩個 使用者介面自動化 元素,若兩者指向同一 UI 元素,則回傳 true。

public:
 static bool Compare(System::Windows::Automation::AutomationElement ^ el1, System::Windows::Automation::AutomationElement ^ el2);
public static bool Compare(System.Windows.Automation.AutomationElement el1, System.Windows.Automation.AutomationElement el2);
static member Compare : System.Windows.Automation.AutomationElement * System.Windows.Automation.AutomationElement -> bool
Public Shared Function Compare (el1 As AutomationElement, el2 As AutomationElement) As Boolean

參數

el1
AutomationElement

第一個比較的 使用者介面自動化 元素。

el2
AutomationElement

第二個 使用者介面自動化 元素要比較。

傳回

true 如果 UI 元素的執行時識別碼相同;否則 false。

備註

如果任一參數是空參考(Nothing in Visual Basic),Compare 會拋出 ArgumentNullException 例外。

此方法等價於物件的 AutomationElement 等號算子。

另請參閱

適用於