Compartir a través de


IRawElementProviderFragmentRoot.ElementProviderFromPoint Método

Definición

Recupera el elemento de este fragmento que está en el punto especificado.

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

Parámetros

x
Double

Coordenada X.

y
Double

Coordenada Y.

Devoluciones

IRawElementProviderFragment

Proveedor para el elemento secundario en el punto especificado, si existe, o proveedor raíz si el punto está en este elemento pero no en cualquier elemento secundario. De lo contrario, devuelve null.

Ejemplos

En el ejemplo de código siguiente se muestra una posible implementación de este método para un cuadro de lista sin desplazamiento. El índice del elemento de lista en el punto especificado se calcula con el alto de cada elemento y se devuelve el elemento en ese punto. Si no existe ningún elemento en ese punto (por ejemplo, es un área en blanco del cuadro de lista, el método devuelve una referencia nula (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

Comentarios

Si el punto está en un elemento de otro marco hospedado por este fragmento, el método devuelve el elemento que hospeda ese fragmento.

El proveedor devuelto debe corresponder al elemento que recibiría la entrada del mouse en el punto especificado.

Se aplica a

Consulte también