AutomationElement.FromPoint(Point) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在桌面指定點取得使用者 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點的邊界矩形內,但它不一定位於控制點的可點擊區域。 例如,圓形按鈕在其邊界矩形的某個角落附近可能無法點擊。