Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            if (BackColor == Color.Transparent || BackColor.A < 255)
            {
                if (Parent is ISupportsTransparentChildRendering)
                {
                    ((ISupportsTransparentChildRendering)Parent).TransparentChild = this;
                }

                int hScrollHeight = (this.HScroll ? SystemInformation.HorizontalScrollBarHeight : 0);
                int vScrollWidth  = (this.VScroll ? SystemInformation.VerticalScrollBarWidth : 0);

                int borderWidth    = ((this.Width - this.ClientSize.Width) - vScrollWidth) / 2;
                int titleBarHeight = this.Height - this.ClientSize.Height - (2 * borderWidth) - hScrollHeight;

                System.Drawing.Drawing2D.GraphicsContainer g = e.Graphics.BeginContainer();
                Rectangle translateRect = this.Bounds;
                e.Graphics.TranslateTransform(-(Left + borderWidth), -(Top + titleBarHeight + borderWidth));
                PaintEventArgs pe = new PaintEventArgs(e.Graphics, translateRect);
                this.InvokePaintBackground(Parent, pe);
                this.InvokePaint(Parent, pe);
                e.Graphics.ResetTransform();
                e.Graphics.EndContainer(g);
                pe.Dispose();

                if (Parent is ISupportsTransparentChildRendering)
                {
                    ((ISupportsTransparentChildRendering)Parent).TransparentChild = null;
                }
            }

            ControlRenderer.PaintBackgoundColorAndImage(this, e.Graphics, true, DisplayRectangle);

            if (TransparentChild != null && DesignMode)
            {
                ControlRenderer.RenderOwnerDrawnControlsOfParent(e.Graphics, TransparentChild);
            }
        }
Exemplo n.º 2
0
        /// <summary>paint the backround button</summary>
        /// <param name="mgButton"></param>
        /// <param name="e"></param>
        private static void PaintBackground(Control buttonBase, PaintEventArgs e)
        {
            Rectangle displayRect = buttonBase.ClientRectangle;

            // when button is image , the display rect is on all the button, else the display rect is on the tect rect
            if (!ControlUtils.IsImageButton(buttonBase))
            {
                displayRect = GetTextRect(buttonBase);
            }

            ControlRenderer.PaintBackgoundColorAndImage(buttonBase, e.Graphics, false, displayRect);

#if PocketPC
            // Draw the border for the button-appearance checkbox
            if (buttonBase is MgCheckBox)
            {
                Rectangle rect = buttonBase.ClientRectangle;
                rect.Inflate(-1, -1);
                Color        fgColor     = buttonBase.ForeColor;
                ControlStyle borderStyle = (((MgCheckBox)buttonBase).CheckState == CheckState.Unchecked) ? ControlStyle.ThreeD : ControlStyle.TwoD;
                BorderRenderer.PaintBorder(e.Graphics, rect, fgColor, borderStyle, false);
            }
#endif
        }