AutomationElement.GetClickablePoint 方法

定义

检索 AutomationElement 上可以单击的点。Retrieves a point on the AutomationElement that can be clicked.

public:
 System::Windows::Point GetClickablePoint();
public System.Windows.Point GetClickablePoint ();
member this.GetClickablePoint : unit -> System.Windows.Point
Public Function GetClickablePoint () As Point

返回

一个点的物理屏幕坐标,客户端可以使用该点在此元素单击。The physical screen coordinates of a point that can be used by a client to click on this element.

异常

没有可单击的点。There is no clickable point.

AutomationElement 的 UI 不再存在。The UI for the AutomationElement no longer exists.

示例

以下代码将检索控件的可单击点,并将系统光标移动到该点。The following code retrieves a clickable point for a control and moves the system cursor to that point.

// element is an AutomationElement.
System.Windows.Point clickablePoint = element.GetClickablePoint();
System.Windows.Forms.Cursor.Position = 
    new System.Drawing.Point((int)clickablePoint.X, (int)clickablePoint.Y);
' element is an AutomationElement.
Dim clickablePoint As System.Windows.Point = element.GetClickablePoint()
System.Windows.Forms.Cursor.Position = New System.Drawing.Point(CInt(clickablePoint.X), CInt(clickablePoint.Y))

注解

如果它完全被另一个窗口遮盖,则不可单击。AutomationElementAn AutomationElement is not clickable if it is completely obscured by another window.

当满足以下所有条件时,可单击"是":AutomationElementAn AutomationElement is clickable when it satisfies all the following conditions:

  • 它以编程方式可见,并可UI 自动化UI Automation用于树。It is programmatically visible and available with the UI 自动化UI Automation tree.

  • 它在其父容器(如果有)内全部滚动到视图中。It is scrolled fully into view within its parent container, if any. 如果该元素已被剪裁,则无法保证它是可单击的。If the element is clipped, there is no guarantee that it is clickable.

  • 元素未被任何其他 UI 元素遮盖。The element is not obscured by any other UI element. 如果元素由某些 UI 元素部分遮盖,而不是其上级,则它可能无法单击。If the element is partially obscured by some UI element other than its ancestors, it might not be clickable.

  • 包含元素的窗口本身必须是可单击的。The window containing the element must itself be clickable. 例如,如果包含窗口完全透明,则窗口不可单击。For example, the window is not clickable if the containing window is completely transparent. 鼠标单击将依次单击到下窗口,因此透明窗口中的任何控件都不会返回可单击的点。Mouse clicks will click through to the window underneath, so any controls within the transparent window will not return clickable points.

  • 如果元素是容器(如列表或树视图),则它必须具有一个点,单击该点将使控件的背景成为焦点。If the element is a container (such as list or tree view), it must have a point that when clicked will cause the background of the control to be focused. 如果容器控件的每个部分都由子元素占用,则它不可单击。If every part of the container control is occupied by a child element, it is not clickable.

不保证当单击由 UI 自动化提供程序定义为可单击的点时,控件将执行任何操作。There is no guarantee that a control will do anything when clicked on a point defined as clickable by the UI Automation provider. 请考虑使用控件模式来对控件执行操作。Consider using control patterns instead to perform actions on controls.

适用于

另请参阅