AutomationElement.FromPoint(Point) 方法

定義

擷取使用者介面的新 AutomationElement 物件, (UI) 在桌面上的指定點。

public:
 static System::Windows::Automation::AutomationElement ^ FromPoint(System::Windows::Point pt);
public static System.Windows.Automation.AutomationElement FromPoint (System.Windows.Point pt);
static member FromPoint : System.Windows.Point -> System.Windows.Automation.AutomationElement
Public Shared Function FromPoint (pt As Point) As AutomationElement

參數

pt
Point

桌面上的實體螢幕座標,用來找出 UI 元素。

傳回

指定點的 UI 專案。

範例

下列範例會在 AutomationElement 系統資料指標位置擷取 。

private AutomationElement ElementFromCursor()
{
    // Convert mouse position from System.Drawing.Point to System.Windows.Point.
    System.Windows.Point point = new System.Windows.Point(Cursor.Position.X, Cursor.Position.Y);
    AutomationElement element = AutomationElement.FromPoint(point);
    return element;
}
Private Function ElementFromCursor() As AutomationElement
    ' Convert mouse position from System.Drawing.Point to System.Windows.Point.
    Dim cursorPoint As System.Windows.Point = New System.Windows.Point( _
        System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y)
    Return AutomationElement.FromPoint(cursorPoint)
End Function

備註

FromPoint 會傳回最接近根項目之邏輯樹狀結構中的專案。

如果您的用戶端應用程式可能嘗試在自己的使用者介面中尋找元素,您必須在個別執行緒上進行所有消費者介面自動化呼叫。

雖然點位於傳 AutomationElement 回的周框內,但它不一定位於控制項的可點選部分。 例如,在周框矩形的其中一個角落附近,可能無法按一下圓角按鈕。

適用於

另請參閱