コード例 #1
0
        public Point?GetLocation(int accuracy, bool tryReturnIfHidden)
        {
            // Try using APIs first
            Rectangle rect = NotifyIconHelpers.GetNotifyIconRectangle(NotifyIcon, tryReturnIfHidden);

            if (!rect.IsEmpty)
            {
                return(rect.Location);
            }

            // Don't fallback if the icon isn't visible
            if (!tryReturnIfHidden)
            {
                Rectangle rect2 = NotifyIconHelpers.GetNotifyIconRectangle(NotifyIcon, true);
                if (rect2.IsEmpty)
                {
                    return(null);
                }
            }

            // Ugly fallback time :(
            var   finder = new Zhwang.SuperNotifyIcon.Finder.NotifyIconColorFinder(NotifyIcon);
            Point?point  = finder.GetLocation(accuracy);

            if (point.HasValue)
            {
                return(point);
            }

            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Checks whether a point is within the bounds of the specified notify icon.
        /// </summary>
        /// <param name="point">Point to check.</param>
        /// <param name="notifyicon">Notify icon to check.</param>
        /// <returns>True if the point is contained in the bounds, false otherwise.</returns>
        public static bool IsPointInNotifyIcon(Point point, NotifyIcon notifyicon)
        {
            Rectangle?nirect = NotifyIconHelpers.GetNotifyIconRectangle(notifyicon, true);

            if (nirect == null)
            {
                return(false);
            }
            return(((Rectangle)nirect).Contains(point));
        }