Esempio n. 1
0
        public void SetContent(TooltipContentBase content)
        {
            bool wasVisible = Visible;

            Visible = false;

            Content = content;

            var pos = content.Location;
            var sz  = content.Size;

            SetBounds(pos.X, pos.Y, sz.Width, sz.Height);

            UpdateRegion();

            Refresh();

            if (!wasVisible)
            {
                Show(Owner);
            }
            else
            {
                Visible = true;
            }
        }
Esempio n. 2
0
        public void SetContent(TooltipContentBase content)
        {
            bool wasVisible = Visible;
            Visible = false;

            Content = content;

            var pos = content.Location;
            var sz = content.Size;
            SetBounds(pos.X, pos.Y, sz.Width, sz.Height);

            UpdateRegion();

            Refresh();

            if (!wasVisible)
                Show(Owner);
            else
                Visible = true;
        }
Esempio n. 3
0
        public static void FitContentOnScreen(
            Graphics g, TooltipContentBase content, 
            ref Font font, ref Point tooltipPosition,
            ref Size tooltipSize
        )
        {
            var screen = Screen.FromPoint(tooltipPosition);
            var screenBounds = screen.WorkingArea;
            var fontSize = font.Size;
            Font tempFont = null;

            // Iterate a few times to shrink the tooltip's font size if it's too big
            for (int i = 0; i < 10; i++) {
                var size = content.Measure(g);

                tooltipSize.Width = size.Width;
                tooltipSize.Height = size.Height;

                if (fontSize <= MinTooltipSizeEm)
                    break;
                if (size.Width < (screenBounds.Width * MaxTooltipWidthPercent / 100) &&
                    size.Height < (screenBounds.Height * MaxTooltipHeightPercent / 100))
                    break;

                fontSize *= FontSizeShrinkMultiplier;
                if (fontSize < MinTooltipSizeEm)
                    fontSize = MinTooltipSizeEm;

                font = new Font(
                    font.FontFamily,
                    Math.Min(fontSize, MinTooltipSizeEm),
                    font.Style
                );

                if (tempFont != null)
                    tempFont.Dispose();

                tempFont = font;
            }

            var maxWidth = (screenBounds.Width * MaxTooltipWidthPercent / 100);
            var maxHeight = (screenBounds.Height * MaxTooltipHeightPercent / 100);

            if (tooltipSize.Width > maxWidth)
                tooltipSize.Width = maxWidth;
            if (tooltipSize.Height > maxHeight)
                tooltipSize.Height = maxHeight;

            if (tooltipPosition.X < screenBounds.Left)
                tooltipPosition.X = screenBounds.Left;
            if (tooltipPosition.Y < screenBounds.Top)
                tooltipPosition.Y = screenBounds.Top;

            if ((tooltipPosition.X + tooltipSize.Width) >= screenBounds.Right)
                tooltipPosition.X = (screenBounds.Right - tooltipSize.Width - 1);
            if ((tooltipPosition.Y + tooltipSize.Height) >= screenBounds.Bottom)
                tooltipPosition.Y = (screenBounds.Bottom - tooltipSize.Height - 1);
        }
Esempio n. 4
0
        public static void FitContentOnScreen(
            Graphics g, TooltipContentBase content,
            ref Font font, ref Point tooltipPosition,
            ref Size tooltipSize
            )
        {
            var  screen       = Screen.FromPoint(tooltipPosition);
            var  screenBounds = screen.WorkingArea;
            var  fontSize     = font.Size;
            Font tempFont     = null;

            // Iterate a few times to shrink the tooltip's font size if it's too big
            for (int i = 0; i < 10; i++)
            {
                var size = content.Measure(g);

                tooltipSize.Width  = size.Width;
                tooltipSize.Height = size.Height;

                if (fontSize <= MinTooltipSizeEm)
                {
                    break;
                }
                if (size.Width < (screenBounds.Width * MaxTooltipWidthPercent / 100) &&
                    size.Height < (screenBounds.Height * MaxTooltipHeightPercent / 100))
                {
                    break;
                }

                fontSize *= FontSizeShrinkMultiplier;
                if (fontSize < MinTooltipSizeEm)
                {
                    fontSize = MinTooltipSizeEm;
                }

                font = new Font(
                    font.FontFamily,
                    Math.Min(fontSize, MinTooltipSizeEm),
                    font.Style
                    );

                if (tempFont != null)
                {
                    tempFont.Dispose();
                }

                tempFont = font;
            }

            var maxWidth  = (screenBounds.Width * MaxTooltipWidthPercent / 100);
            var maxHeight = (screenBounds.Height * MaxTooltipHeightPercent / 100);

            if (tooltipSize.Width > maxWidth)
            {
                tooltipSize.Width = maxWidth;
            }
            if (tooltipSize.Height > maxHeight)
            {
                tooltipSize.Height = maxHeight;
            }

            if (tooltipPosition.X < screenBounds.Left)
            {
                tooltipPosition.X = screenBounds.Left;
            }
            if (tooltipPosition.Y < screenBounds.Top)
            {
                tooltipPosition.Y = screenBounds.Top;
            }

            if ((tooltipPosition.X + tooltipSize.Width) >= screenBounds.Right)
            {
                tooltipPosition.X = (screenBounds.Right - tooltipSize.Width - 1);
            }
            if ((tooltipPosition.Y + tooltipSize.Height) >= screenBounds.Bottom)
            {
                tooltipPosition.Y = (screenBounds.Bottom - tooltipSize.Height - 1);
            }
        }