Example #1
0
 public virtual void Paint(Graphics g, RectangleF bounds, SizeF dpiScale)
 {
     lock (Locker.SyncObj)
     {
         Rectangle paintRect = LayoutUtils.DeflateRect(Rectangle.Round(bounds), this.padding);
         this.dpiScale = dpiScale;
         if (paintRect.Width <= 0 || paintRect.Height <= 0)
         {
             return;
         }
         InterpolationMode interpolationMode = g.InterpolationMode;
         g.InterpolationMode = this.interpolationMode;
         if (this.imageDirty)
         {
             this.ResetImageCache();
         }
         if (this.segmentsDirty)
         {
             this.ResetSegments();
         }
         if (this.cachedImage != null)
         {
             this.PaintCore(g, paintRect);
         }
         g.InterpolationMode = interpolationMode;
     }
 }
Example #2
0
        /// <include file='doc\ToolStripControlHost.uex' path='docs/doc[@for="ToolStripControlHost.OnBoundsChanged"]/*' />
        /// <devdoc>
        /// Called when the items bounds are changed.  Here, we update the Control's bounds.
        /// </devdoc>
        protected override void OnBoundsChanged()
        {
            if (control != null)
            {
                SuspendSizeSync();
                IArrangedElement element = control as IArrangedElement;
                if (element == null)
                {
                    Debug.Fail("why are we here? control should not be null");
                    return;
                }

                Size      size   = LayoutUtils.DeflateRect(this.Bounds, this.Padding).Size;
                Rectangle bounds = LayoutUtils.Align(size, this.Bounds, ControlAlign);

                // use BoundsSpecified.None so we dont deal w/specified bounds - this way we can tell what someone has set the size to.
                element.SetBounds(bounds, BoundsSpecified.None);

                // sometimes a control can ignore the size passed in, use the adjustment
                // to re-align.
                if (bounds != control.Bounds)
                {
                    bounds = LayoutUtils.Align(control.Size, this.Bounds, ControlAlign);
                    element.SetBounds(bounds, BoundsSpecified.None);
                }
                ResumeSizeSync();
            }
        }
 protected virtual RectangleF ModifyBorderAndFillPaintRect(
     RectangleF preferred,
     Padding padding)
 {
     if (this.borderAndFillOrientation == PageViewContentOrientation.Vertical90 || this.borderAndFillOrientation == PageViewContentOrientation.Vertical270)
     {
         preferred.Size = new SizeF(preferred.Height, preferred.Width);
     }
     return(LayoutUtils.DeflateRect(preferred, padding));
 }
Example #4
0
        protected virtual RectangleF ArrangeContent(RectangleF clientRect)
        {
            if (this.contentArea.Visibility != ElementVisibility.Collapsed)
            {
                clientRect = LayoutUtils.DeflateRect(clientRect, this.contentArea.Margin);
                this.contentArea.Arrange(clientRect);
                if (this.selectedItem != null && this.owner != null)
                {
                    this.selectedItem.Page.Bounds = this.GetContentAreaRectangle();
                }
            }

            return(clientRect);
        }
 protected override void OnBoundsChanged()
 {
     if (this.control != null)
     {
         this.SuspendSizeSync();
         IArrangedElement control = this.control;
         if (control != null)
         {
             Rectangle bounds = LayoutUtils.Align(LayoutUtils.DeflateRect(this.Bounds, this.Padding).Size, this.Bounds, this.ControlAlign);
             control.SetBounds(bounds, BoundsSpecified.None);
             if (bounds != this.control.Bounds)
             {
                 bounds = LayoutUtils.Align(this.control.Size, this.Bounds, this.ControlAlign);
                 control.SetBounds(bounds, BoundsSpecified.None);
             }
             this.ResumeSizeSync();
         }
     }
 }
Example #6
0
        private Rectangle ImageRectangleFromSizeMode(PictureBoxSizeMode mode)
        {
            Rectangle rectangle = LayoutUtils.DeflateRect(base.ClientRectangle, base.Padding);

            if (this.image != null)
            {
                switch (mode)
                {
                case PictureBoxSizeMode.Normal:
                case PictureBoxSizeMode.AutoSize:
                    rectangle.Size = this.image.Size;
                    return(rectangle);

                case PictureBoxSizeMode.StretchImage:
                    return(rectangle);

                case PictureBoxSizeMode.CenterImage:
                    rectangle.X   += (rectangle.Width - this.image.Width) / 2;
                    rectangle.Y   += (rectangle.Height - this.image.Height) / 2;
                    rectangle.Size = this.image.Size;
                    return(rectangle);

                case PictureBoxSizeMode.Zoom:
                {
                    Size  size = this.image.Size;
                    float num  = Math.Min((float)(((float)base.ClientRectangle.Width) / ((float)size.Width)), (float)(((float)base.ClientRectangle.Height) / ((float)size.Height)));
                    rectangle.Width  = (int)(size.Width * num);
                    rectangle.Height = (int)(size.Height * num);
                    rectangle.X      = (base.ClientRectangle.Width - rectangle.Width) / 2;
                    rectangle.Y      = (base.ClientRectangle.Height - rectangle.Height) / 2;
                    return(rectangle);
                }
                }
            }
            return(rectangle);
        }
Example #7
0
        protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs e)
        {
            ToolStrip            toolStrip = e.ToolStrip;
            ToolStripSplitButton item      = e.Item as ToolStripSplitButton;

            if (item != null)
            {
                Graphics           graphics = e.Graphics;
                LinearGradientMode mode     = (toolStrip.Orientation == Orientation.Horizontal) ? LinearGradientMode.Vertical : LinearGradientMode.Horizontal;
                Rectangle          bounds   = new Rectangle(Point.Empty, item.Size);
                new SmoothingModeGraphics(graphics);
                Color arrowColor = toolStrip.Enabled ? this.ColorTable.Fore : SystemColors.ControlDark;
                if (item.BackgroundImage != null)
                {
                    Rectangle clipRect = item.Selected ? item.ContentRectangle : bounds;
                    ControlPaintEx.DrawBackgroundImage(graphics, item.BackgroundImage, this.ColorTable.Back, item.BackgroundImageLayout, bounds, clipRect);
                }
                if (item.ButtonPressed)
                {
                    if (this.ColorTable.BaseItemDown != null)
                    {
                        ImageDrawRect.DrawRect(graphics, (Bitmap)this.ColorTable.BaseItemDown, bounds, Rectangle.FromLTRB(this.ColorTable.BackRectangle.X, this.ColorTable.BackRectangle.Y, this.ColorTable.BackRectangle.Width, this.ColorTable.BackRectangle.Height), 1, 1);
                    }
                    else
                    {
                        Rectangle buttonBounds = item.ButtonBounds;
                        Padding   padding      = (item.RightToLeft == RightToLeft.Yes) ? new Padding(0, 1, 1, 1) : new Padding(1, 1, 0, 1);
                        buttonBounds = LayoutUtils.DeflateRect(buttonBounds, padding);
                        RenderHelperStrip.RenderBackgroundInternal(graphics, bounds, this.ColorTable.BaseItemHover, this.ColorTable.BaseItemBorder, this.ColorTable.Back, this.ColorTable.BaseItemRadiusStyle, this.ColorTable.BaseItemRadius, this.ColorTable.BaseItemBorderShow, this.ColorTable.BaseItemAnamorphosis, mode);
                        buttonBounds.Inflate(-1, -1);
                        graphics.SetClip(buttonBounds);
                        RenderHelperStrip.RenderBackgroundInternal(graphics, buttonBounds, this.ColorTable.BaseItemPressed, this.ColorTable.BaseItemBorder, this.ColorTable.Back, RoundStyle.Left, false, true, mode);
                        graphics.ResetClip();
                        using (Pen pen = new Pen(this.ColorTable.BaseItemSplitter))
                        {
                            graphics.DrawLine(pen, item.SplitterBounds.Left, item.SplitterBounds.Top, item.SplitterBounds.Left, item.SplitterBounds.Bottom);
                        }
                    }
                    base.DrawArrow(new ToolStripArrowRenderEventArgs(graphics, item, item.DropDownButtonBounds, arrowColor, ArrowDirection.Down));
                }
                else if (!item.Pressed && !item.DropDownButtonPressed)
                {
                    if (item.Selected)
                    {
                        if (this.ColorTable.BaseItemMouse != null)
                        {
                            ImageDrawRect.DrawRect(graphics, (Bitmap)this.ColorTable.BaseItemMouse, bounds, Rectangle.FromLTRB(this.ColorTable.BackRectangle.X, this.ColorTable.BackRectangle.Y, this.ColorTable.BackRectangle.Width, this.ColorTable.BackRectangle.Height), 1, 1);
                        }
                        else
                        {
                            RenderHelperStrip.RenderBackgroundInternal(graphics, bounds, this.ColorTable.BaseItemHover, this.ColorTable.BaseItemBorder, this.ColorTable.Back, this.ColorTable.BaseItemRadiusStyle, this.ColorTable.BaseItemRadius, this.ColorTable.BaseItemBorderShow, this.ColorTable.BaseItemAnamorphosis, mode);
                            using (Pen pen2 = new Pen(this.ColorTable.BaseItemSplitter))
                            {
                                graphics.DrawLine(pen2, item.SplitterBounds.Left, item.SplitterBounds.Top, item.SplitterBounds.Left, item.SplitterBounds.Bottom);
                            }
                        }
                        base.DrawArrow(new ToolStripArrowRenderEventArgs(graphics, item, item.DropDownButtonBounds, arrowColor, ArrowDirection.Down));
                    }
                    else
                    {
                        base.DrawArrow(new ToolStripArrowRenderEventArgs(graphics, item, item.DropDownButtonBounds, arrowColor, ArrowDirection.Down));
                    }
                }
                else
                {
                    if (this.ColorTable.BaseItemDown != null)
                    {
                        ImageDrawRect.DrawRect(graphics, (Bitmap)this.ColorTable.BaseItemDown, bounds, Rectangle.FromLTRB(this.ColorTable.BackRectangle.X, this.ColorTable.BackRectangle.Y, this.ColorTable.BackRectangle.Width, this.ColorTable.BackRectangle.Height), 1, 1);
                    }
                    else
                    {
                        RenderHelperStrip.RenderBackgroundInternal(graphics, bounds, this.ColorTable.BaseItemPressed, this.ColorTable.BaseItemBorder, this.ColorTable.Back, this.ColorTable.BaseItemRadiusStyle, this.ColorTable.BaseItemRadius, this.ColorTable.BaseItemBorderShow, this.ColorTable.BaseItemAnamorphosis, mode);
                    }
                    base.DrawArrow(new ToolStripArrowRenderEventArgs(graphics, item, item.DropDownButtonBounds, arrowColor, ArrowDirection.Down));
                }
            }
            else
            {
                base.OnRenderSplitButtonBackground(e);
            }
        }
Example #8
0
        private Size xLayoutRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, int endIndex, Rectangle rowBounds, out int breakIndex, bool measureOnly)
        {
            Point location = rowBounds.Location;
            Size  empty    = Size.Empty;
            int   num      = 0;

            breakIndex = startIndex;
            bool wrapContents = GetWrapContents(containerProxy.Container);
            bool flag2        = false;
            ArrangedElementCollection children = containerProxy.Container.Children;
            int num2 = startIndex;

            while (num2 < endIndex)
            {
                elementProxy.Element = children[num2];
                if (elementProxy.ParticipatesInLayout)
                {
                    Size preferredSize;
                    if (elementProxy.AutoSize)
                    {
                        Size b = new Size(0x7fffffff, rowBounds.Height - elementProxy.Margin.Size.Height);
                        if (num2 == startIndex)
                        {
                            b.Width = (rowBounds.Width - empty.Width) - elementProxy.Margin.Size.Width;
                        }
                        b             = LayoutUtils.UnionSizes(new Size(1, 1), b);
                        preferredSize = elementProxy.GetPreferredSize(b);
                    }
                    else
                    {
                        preferredSize = elementProxy.SpecifiedSize;
                        if (elementProxy.Stretches)
                        {
                            preferredSize.Height = 0;
                        }
                        if (preferredSize.Height < elementProxy.MinimumSize.Height)
                        {
                            preferredSize.Height = elementProxy.MinimumSize.Height;
                        }
                    }
                    Size size4 = preferredSize + elementProxy.Margin.Size;
                    if (!measureOnly)
                    {
                        Rectangle rect = new Rectangle(location, new Size(size4.Width, rowBounds.Height));
                        rect = LayoutUtils.DeflateRect(rect, elementProxy.Margin);
                        AnchorStyles anchorStyles = elementProxy.AnchorStyles;
                        containerProxy.Bounds = LayoutUtils.AlignAndStretch(preferredSize, rect, anchorStyles);
                    }
                    location.X += size4.Width;
                    if ((num > 0) && (location.X > rowBounds.Right))
                    {
                        return(empty);
                    }
                    empty.Width  = location.X - rowBounds.X;
                    empty.Height = Math.Max(empty.Height, size4.Height);
                    if (wrapContents)
                    {
                        if (flag2)
                        {
                            return(empty);
                        }
                        if (((num2 + 1) < endIndex) && CommonProperties.GetFlowBreak(elementProxy.Element))
                        {
                            if (num == 0)
                            {
                                flag2 = true;
                            }
                            else
                            {
                                breakIndex++;
                                return(empty);
                            }
                        }
                    }
                    num++;
                }
                num2++;
                breakIndex++;
            }
            return(empty);
        }
Example #9
0
 private Rectangle GetClientRect()
 {
     return(LayoutUtils.DeflateRect(this.ClientRectangle, this.Padding));
 }
Example #10
0
        private Rectangle GetClientRect()
        {
            Rectangle client = this.ClientRectangle;

            return(LayoutUtils.DeflateRect(client, this.Padding));
        }
Example #11
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Color nearestColor;

            this.Animate();
            Rectangle r = LayoutUtils.DeflateRect(base.ClientRectangle, base.Padding);

            ImageAnimator.UpdateFrames();
            System.Drawing.Image image = this.Image;
            if (image != null)
            {
                this.DrawImage(e.Graphics, image, r, base.RtlTranslateAlignment(this.ImageAlign));
            }
            IntPtr hdc = e.Graphics.GetHdc();

            try
            {
                using (WindowsGraphics graphics = WindowsGraphics.FromHdc(hdc))
                {
                    nearestColor = graphics.GetNearestColor(base.Enabled ? this.ForeColor : base.DisabledColor);
                }
            }
            finally
            {
                e.Graphics.ReleaseHdc();
            }
            if (this.AutoEllipsis)
            {
                Rectangle clientRectangle = base.ClientRectangle;
                Size      preferredSize   = this.GetPreferredSize(new Size(clientRectangle.Width, clientRectangle.Height));
                this.showToolTip = (clientRectangle.Width < preferredSize.Width) || (clientRectangle.Height < preferredSize.Height);
            }
            else
            {
                this.showToolTip = false;
            }
            if (this.UseCompatibleTextRendering)
            {
                using (StringFormat format = this.CreateStringFormat())
                {
                    if (base.Enabled)
                    {
                        using (Brush brush = new SolidBrush(nearestColor))
                        {
                            e.Graphics.DrawString(this.Text, this.Font, brush, r, format);
                            goto Label_01BF;
                        }
                    }
                    ControlPaint.DrawStringDisabled(e.Graphics, this.Text, this.Font, nearestColor, r, format);
                    goto Label_01BF;
                }
            }
            TextFormatFlags flags = this.CreateTextFormatFlags();

            if (base.Enabled)
            {
                TextRenderer.DrawText(e.Graphics, this.Text, this.Font, r, nearestColor, flags);
            }
            else
            {
                Color foreColor = TextRenderer.DisabledTextColor(this.BackColor);
                TextRenderer.DrawText(e.Graphics, this.Text, this.Font, r, foreColor, flags);
            }
Label_01BF:
            base.OnPaint(e);
        }