示例#1
0
        private RectSet GetAdjustedRects(bool returnIfAnchored)
        {
            var parentSize     = Size;
            var parentLocation = Location;

            var childSize     = Editor.Control.Size;
            var childLocation = new Point(CalculatedPadding.Left, CalculatedPadding.Top);

            // --- Anchored

            // If we're anchored to two opposite sides of the form, don't adjust the size because
            // we'll lose our anchored size by resetting to the requested width.
            if (returnIfAnchored &&
                (Anchor & (AnchorStyles.Top | AnchorStyles.Bottom)) == (AnchorStyles.Top | AnchorStyles.Bottom))
            {
                return(new RectSet(new Rectangle(parentLocation, parentSize), new Rectangle(childLocation, childSize)));
            }

            var lrPad = CalculatedPadding.Left + CalculatedPadding.Right;
            var tbPad = CalculatedPadding.Top + CalculatedPadding.Bottom;

            // --- Multiline

            if (Multiline)
            {
                childSize = new Size(parentSize.Width - lrPad,
                                     parentSize.Height - tbPad);

                return(new RectSet(new Rectangle(parentLocation, parentSize), new Rectangle(childLocation, childSize)));
            }

            // --- Singleline

            var fontSize = FontSizeConverter.GetWinFormsFontSize(Editor.FontSize);
            var font     = new Font(Font.FontFamily, (float)fontSize, Font.Style, GraphicsUnit.Point, Font.GdiCharSet, Font.GdiVerticalFont);

            Size measuredTextSize;

            using (var g = CreateGraphics())
            {
                var size = g.MeasureString("MQ", font);
                measuredTextSize = new Size((int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height));
            }

            var parentWidth  = parentSize.Width;
            var parentHeight = (int)Math.Ceiling((double)measuredTextSize.Height);

            parentSize = new Size(parentWidth,
                                  parentHeight + tbPad);

            childSize = new Size(parentWidth + Editor.VerticalScrollBarWidthAllowance - lrPad,
                                 parentHeight + Editor.HorizontalScrollBarHeightAllowance);

            return(new RectSet(new Rectangle(parentLocation, parentSize), new Rectangle(childLocation, childSize)));
        }