语言

AutomationElement.FromPoint(Point) 方法

定义

检索桌面上指定点用户界面(UI)项的新 AutomationElement 对象。

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 返回最接近根元素的逻辑树中的元素。

如果客户端应用程序可能尝试在其自己的用户界面中查找元素,则必须对单独的线程进行所有UI 自动化调用。

虽然该点位于返回 AutomationElement的边框内,但它不一定位于控件的可单击部分。 例如,圆圆按钮可能不可单击其边界矩形的一个角附近。

适用于

另请参阅