IRawElementProviderFragmentRoot.ElementProviderFromPoint Method (Double, Double)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Retrieves the element in this fragment that is at the specified point.

Namespace:   System.Windows.Automation.Provider
Assembly:  UIAutomationProvider (in UIAutomationProvider.dll)

IRawElementProviderFragment ElementProviderFromPoint(
	double x,
	double y


Type: System.Double

The X coordinate,.

Type: System.Double

The Y coordinate.

Return Value

Type: System.Windows.Automation.Provider.IRawElementProviderFragment

The provider for the child element at the specified point, if one exists, or the root provider if the point is on this element but not on any child element. Otherwise returns null.

If the point is on an element in another framework that is hosted by this fragment, the method returns the element that hosts that fragment.

The returned provider should correspond to the element that would receive mouse input at the specified point.

The following code example shows one possible implementation of this method for a non-scrolling list box. The index of the list item at the specified point is calculated using the height of each item, and the item at that point is returned. If no item exists at that point (for example, it is a blank area of the list box, the method returns a null reference (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;

.NET Framework
Available since 3.0
Return to top