Esempio n. 1
0
        public static bool InterceptWith(this FrameworkElement element, FrameworkElement secondElement)
        {
            var point1 = element.PointToScreen(new Point(0, 0));
            var point2 = secondElement.PointToScreen(new Point(0, 0));

            var dpiX = SystemParams.GetDpiX();
            var dpiY = SystemParams.GetDpiY();

            point1.X = point1.X * 96.0 / dpiX;
            point1.Y = point1.Y * 96.0 / dpiY;

            point2.X = point2.X * 96.0 / dpiX;
            point2.Y = point2.Y * 96.0 / dpiY;

            var rect = new Rect
            {
                Location = new Point(point1.X, point1.Y),
                Size     = new Size(element.ActualWidth, element.ActualHeight)
            };

            var rect2 = new Rect
            {
                Location = new Point(point2.X, point2.Y),
                Size     = new Size(secondElement.ActualWidth, secondElement.ActualHeight)
            };

            var a = rect.IntersectsWith(rect2);


            return(a);
        }
Esempio n. 2
0
        private void TrayContextMenu_Activated(object sender, EventArgs e)
        {
            var mouseX = Control.MousePosition.X * 96 / SystemParams.GetDpiX();
            var mouseY = Control.MousePosition.Y * 96 / SystemParams.GetDpiY();

            Left = mouseX - ActualWidth < 0 ? mouseX : mouseX - ActualWidth;
            Top  = mouseY - ActualHeight < 0 ? mouseY : mouseY - ActualHeight;
        }