Export (0) Print
Expand All

IRawElementProviderFragmentRoot.ElementProviderFromPoint Method

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
)

Parameters

x
Type: System.Double

The X coordinate,.

y
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

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft