Condividi tramite


IRawElementProviderFragmentRoot.ElementProviderFromPoint Metodo

Definizione

Recupera l'elemento nel frammento che si trova nel punto specificato.

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

Parametri

x
Double

La coordinata X.

y
Double

La coordinata Y.

Restituisce

IRawElementProviderFragment

Provider per l'elemento figlio nel punto specificato, se presente, o il provider radice se il punto si trova in questo elemento ma non in alcuno degli elementi figlio. In caso contrario restituisce null.

Esempio

Nell'esempio di codice seguente viene illustrata una possibile implementazione di questo metodo per una casella di riepilogo senza scorrimento. L'indice dell'elemento di elenco in corrispondenza del punto specificato viene calcolato utilizzando l'altezza di ogni elemento e l'elemento in quel punto viene restituito. Se a quel punto non esiste alcun elemento, ad esempio è un'area vuota della casella di riepilogo, il metodo restituisce un riferimento 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

Commenti

Se il punto si trova su un elemento in un altro framework ospitato da questo frammento, il metodo restituisce l'elemento che ospita tale frammento.

Il provider restituito deve corrispondere all'elemento che riceverà l'input del mouse nel punto specificato.

Si applica a

Vedi anche