Ejemplo n.º 1
0
        private void UpdateLocation()
        {
            AutoSizeMode = AutoSizeMode.GrowAndShrink;

            var clientSize = ClientRectangle.Size;

            if (CanBalloonFitOnTopOfTarget(clientSize, anchorScreen))
            {
                tailLocation = TailLocation.Bottom;

                var windowSize = SizeFromClientSize(clientSize, tailLocation);
                var x          = anchorBounds.Left - ((windowSize.Width - anchorBounds.Width) / 2);
                x = Math.Max(x, anchorScreen.Bounds.Left);
                x = Math.Min(x, anchorScreen.Bounds.Right - windowSize.Width);
                SetBounds(x, anchorBounds.Top - windowSize.Height, windowSize.Width, windowSize.Height);
            }
            else if (CanBalloonFitOnRightOfTarget(clientSize, anchorScreen))
            {
                tailLocation = TailLocation.Left;

                var windowSize = SizeFromClientSize(clientSize, tailLocation);
                var y          = anchorBounds.Top - ((windowSize.Height - anchorBounds.Height) / 2);
                y = Math.Max(y, anchorScreen.Bounds.Top);
                y = Math.Min(y, anchorScreen.Bounds.Bottom - windowSize.Height);
                SetBounds(anchorBounds.Right, y, windowSize.Width, windowSize.Height);
            }
            else
            {
                tailLocation = TailLocation.Right;

                var windowSize = SizeFromClientSize(clientSize, tailLocation);
                var y          = anchorBounds.Top - ((windowSize.Height - anchorBounds.Height) / 2);
                y = Math.Max(y, anchorScreen.Bounds.Top);
                y = Math.Min(y, anchorScreen.Bounds.Bottom - windowSize.Height);
                SetBounds(anchorBounds.Left - windowSize.Width, y, windowSize.Width, windowSize.Height);
            }

            AutoSizeMode = AutoSizeMode.GrowOnly;
        }
Ejemplo n.º 2
0
        private Size SizeFromClientSize(Size clientSize, TailLocation tail)
        {
            // This would normally adjust the size based on the border styles. Since
            // we don't have a system border, adjust for our non-client area
            var rc = new Rectangle(new Point(0, 0), clientSize);

            rc.Inflate(BalloonMargin, BalloonMargin);
            switch (tail)
            {
            case TailLocation.Left:
                rc.Width += TailLength;
                break;

            case TailLocation.Bottom:
                rc.Height += TailLength;
                break;

            case TailLocation.Right:
                rc.Width += TailLength;
                break;
            }
            return(rc.Size);
        }