IRawElementProviderFragmentRoot.ElementProviderFromPoint 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
检索此片段中位于指定点处的元素。
public:
System::Windows::Automation::Provider::IRawElementProviderFragment ^ ElementProviderFromPoint(double x, double y);
public System.Windows.Automation.Provider.IRawElementProviderFragment ElementProviderFromPoint (double x, double y);
abstract member ElementProviderFromPoint : double * double -> System.Windows.Automation.Provider.IRawElementProviderFragment
Public Function ElementProviderFromPoint (x As Double, y As Double) As IRawElementProviderFragment
参数
- x
- Double
X 坐标。
- y
- Double
Y 坐标。
返回
位于指定点处的子元素的提供程序(如果存在),或者根提供程序(如果该点位于此元素上,而不是位于任何子元素上)。 否则返回 null
。
示例
下面的代码示例演示了非滚动列表框此方法的一个可能实现。 列表项在指定点的索引是使用每个项的高度计算的,此时返回的项。 例如,如果该点不存在项 (,则它是列表框的空白区域,该方法将返回 null 引用 (Nothing
) 。
delegate Rectangle MyDelegate(Rectangle clientRect);
/// <summary>
/// Gets the child element that is at the specified point.
/// </summary>
/// <param name="x">Distance from the left of the application window.</param>
/// <param name="y">Distance from the top of the application window.</param>
/// <returns>The provider for the element at that point.</returns>
IRawElementProviderFragment IRawElementProviderFragmentRoot.ElementProviderFromPoint(
double x, double y)
{
// The RectangleToScreen method on the control can't be called directly from
// this thread, so use delegation.
MyDelegate del = new MyDelegate(this.RectangleToScreen);
Rectangle screenRectangle = (Rectangle)this.Invoke(del, new object[] { this.DisplayRectangle });
if (screenRectangle.Contains((int)x, (int)y))
{
int index = (int)(((int)(y - screenRectangle.Y)) / itemHeight);
if (index < myItems.Count)
{
return (IRawElementProviderFragment)myItems[index];
}
else
{
return (IRawElementProviderFragment)this;
}
}
else
{
return null;
}
}
Delegate Function MyDelegate(ByVal clientRect As Rectangle) As Rectangle
''' <summary>
''' Gets the child element that is at the specified point.
''' </summary>
''' <param name="x">Distance from the left of the application window.</param>
''' <param name="y">Distance from the top of the application window.</param>
''' <returns>The provider for the element at that point.</returns>
Function ElementProviderFromPoint(ByVal x As Double, ByVal y As Double) As IRawElementProviderFragment _
Implements IRawElementProviderFragmentRoot.ElementProviderFromPoint
Dim pointX As Integer = CInt(x)
Dim pointY As Integer = CInt(y)
' The RectangleToScreen method on the control can't be called directly from
' this thread, so use delegation.
Dim converterDelegate As MyDelegate = New MyDelegate(AddressOf Me.RectangleToScreen)
Dim screenRectangle As Rectangle = DirectCast(Me.Invoke(converterDelegate, _
New Object() {Me.DisplayRectangle}), Rectangle)
If screenRectangle.Contains(pointX, pointY) Then
Dim index As Integer = CInt((pointY - screenRectangle.Y) \ itemHeight)
If index < myItems.Count Then
Return DirectCast(myItems(index), IRawElementProviderFragment)
Else
Return DirectCast(Me, IRawElementProviderFragment)
End If
Else
Return Nothing
End If
End Function
注解
如果点位于此片段托管的另一个框架中的元素上,该方法将返回承载该片段的元素。
返回的提供程序应对应于将在指定点接收鼠标输入的元素。