System.Windows.Automation.AutomationElement.FromPoint C# (CSharp) Method

FromPoint() public static method

public static FromPoint ( System.Point pt ) : AutomationElement
pt System.Point
return AutomationElement
        public static AutomationElement FromPoint(Point pt)
        {
            try
            {
                UIAutomationClient.IUIAutomationElement element =
                    Automation.Factory.ElementFromPointBuildCache(
                        Utility.PointManagedToNative(pt),
                        CacheRequest.CurrentNativeCacheRequest);
                return AutomationElement.Wrap(element);
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
            }
        }

Usage Example

        private static bool TryPoint(ref Point pt, AutomationElement el, out AutomationElement hitEl)
        {
            // If the element is obscured by another window or hidden somehow when we try to hit test we don't get back
            //  the same element.  We want to make sure if someone clicks they click on what they expected to click on.
            hitEl = AutomationElement.FromPoint(pt);

            return(hitEl == el);
        }