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
備註
如果此點位於此片段所裝載之另一個架構中的專案上,此方法會傳回裝載該片段的專案。
傳回的提供者應該對應至在指定點接收滑鼠輸入的專案。