示例#1
0
        public bool AutoSize(int availableWidth, int maxWidth)
        {
            bool tooSmall = false;
            bool wordWrap = false;
            Size txtSize  = WinFormUtils.MeasureRichTextBox(toolTipRTB, false, toolTipRTB.Width, toolTipRTB.Height, false);

            // tooltip larger than the window: wrap
            int limitLeft   = ((Form)PluginBase.MainForm).ClientRectangle.Left + 10;
            int limitRight  = ((Form)PluginBase.MainForm).ClientRectangle.Right - 10;
            int limitBottom = ((Form)PluginBase.MainForm).ClientRectangle.Bottom - 26;
            //
            int maxW = availableWidth > 0 ? availableWidth : limitRight - limitLeft;

            if (maxW > maxWidth && maxWidth > 0)
            {
                maxW = maxWidth;
            }

            int w = txtSize.Width + 4;

            if (w > maxW)
            {
                wordWrap = true;
                w        = maxW;
                if (w < 200)
                {
                    w        = 200;
                    tooSmall = true;
                }

                txtSize = WinFormUtils.MeasureRichTextBox(toolTipRTB, false, w, 1000, true);
                w       = txtSize.Width + 4;
            }

            int h  = txtSize.Height + 2;
            int dh = 1;
            int dw = 2;

            if (h > (limitBottom - toolTip.Top))
            {
                w += 15;
                h  = limitBottom - toolTip.Top;
                dh = 4;
                dw = 5;

                toolTipRTB.ScrollBars = RichTextBoxScrollBars.Vertical;
            }

            toolTipRTB.Size = new Size(w, h);
            toolTip.Size    = new Size(w + dw, h + dh);

            if (toolTip.Left < limitLeft)
            {
                toolTip.Left = limitLeft;
            }

            if (toolTip.Left + toolTip.Width > limitRight)
            {
                toolTip.Left = limitRight - toolTip.Width;
            }

            if (toolTipRTB.WordWrap != wordWrap)
            {
                toolTipRTB.WordWrap = wordWrap;
            }

            return(!tooSmall);
        }
示例#2
0
        public bool AutoSize(int availableWidth, int maxWidth)
        {
            bool tooSmall = false;
            bool wordWrap = false;
            Size txtSize  = WinFormUtils.MeasureRichTextBox(toolTipRTB, false, toolTipRTB.Width, toolTipRTB.Height, false);

            int smallOffsetH  = ScaleHelper.Scale(1);
            int smallOffsetW  = ScaleHelper.Scale(2);
            int smallPadding  = ScaleHelper.Scale(4);
            int mediumPadding = ScaleHelper.Scale(10);
            int minWidth      = ScaleHelper.Scale(200);

            maxWidth = ScaleHelper.Scale(maxWidth);

            // tooltip larger than the window: wrap
            int limitLeft   = ((Form)PluginBase.MainForm).ClientRectangle.Left + mediumPadding;
            int limitRight  = ((Form)PluginBase.MainForm).ClientRectangle.Right - mediumPadding;
            int limitBottom = ((Form)PluginBase.MainForm).ClientRectangle.Bottom - ScaleHelper.Scale(26);

            int maxW = availableWidth > 0 ? availableWidth : limitRight - limitLeft;

            if (maxW > maxWidth && maxWidth > 0)
            {
                maxW = maxWidth;
            }

            int w = txtSize.Width + smallPadding;

            if (w > maxW)
            {
                wordWrap = true;
                w        = maxW;
                if (w < minWidth)
                {
                    w        = minWidth;
                    tooSmall = true;
                }

                txtSize = WinFormUtils.MeasureRichTextBox(toolTipRTB, false, w, maxWidth, true);
                w       = txtSize.Width + smallPadding;
            }

            int h  = txtSize.Height + smallOffsetH * 2;
            int dh = smallOffsetH;
            int dw = smallOffsetW;

            if (h > (limitBottom - toolTip.Top))
            {
                w += ScaleHelper.Scale(15);
                h  = limitBottom - toolTip.Top;
                dh = smallPadding;
                dw = smallPadding + smallOffsetW / 2;

                toolTipRTB.ScrollBars = RichTextBoxScrollBars.Vertical;
            }

            toolTipRTB.Location = new Point(smallOffsetW, smallOffsetH);
            toolTipRTB.Size     = new Size(w, h);
            toolTip.Size        = new Size(w + dw, h + dh);

            if (toolTip.Left < limitLeft)
            {
                toolTip.Left = limitLeft;
            }

            if (toolTip.Left + toolTip.Width > limitRight)
            {
                toolTip.Left = limitRight - toolTip.Width;
            }

            if (toolTipRTB.WordWrap != wordWrap)
            {
                toolTipRTB.WordWrap = wordWrap;
            }

            return(!tooSmall);
        }