Ejemplo n.º 1
0
        protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
        {
            ToolStrip toolStrip = e.ToolStrip;
            Graphics  graphics  = e.Graphics;

            if ((toolStrip is ToolStripDropDown) && (e.Item is ToolStripMenuItem))
            {
                Rectangle imageRectangle = e.ImageRectangle;
                if (e.Item.RightToLeft == RightToLeft.Yes)
                {
                    imageRectangle.X -= 2;
                }
                else
                {
                    imageRectangle.X += 2;
                }
                imageRectangle.Width = 13;
                imageRectangle.Y++;
                imageRectangle.Height -= 3;
                using (new SmoothingModeGraphics(graphics))
                {
                    using (GraphicsPath path = new GraphicsPath())
                    {
                        path.AddRectangle(imageRectangle);
                        using (PathGradientBrush brush = new PathGradientBrush(path))
                        {
                            brush.CenterColor    = Color.White;
                            brush.SurroundColors = new Color[] { ControlPaint.Light(this.ColorTable.Back) };
                            Blend   blend    = new Blend();
                            float[] numArray = new float[3];
                            numArray[1]     = 0.3f;
                            numArray[2]     = 1f;
                            blend.Positions = numArray;
                            float[] numArray2 = new float[3];
                            numArray2[1]  = 0.5f;
                            numArray2[2]  = 1f;
                            blend.Factors = numArray2;
                            brush.Blend   = blend;
                            graphics.FillRectangle(brush, imageRectangle);
                        }
                    }
                    using (Pen pen = new Pen(ControlPaint.Light(this.ColorTable.Back)))
                    {
                        graphics.DrawRectangle(pen, imageRectangle);
                    }
                    ControlPaintEx.DrawCheckedFlag(graphics, imageRectangle, this.ColorTable.Fore);
                    return;
                }
            }
            base.OnRenderItemCheck(e);
        }
Ejemplo n.º 2
0
        public static void RenderBackgroundInternal(
            Graphics g,
            Rectangle rect,
            Color baseColor,
            Color borderColor,
            Color innerBorderColor,
            RoundStyle style,
            int roundWidth,
            float basePosition,
            bool drawBorder,
            bool drawGlass,
            LinearGradientMode mode)
        {
            if (drawBorder)
            {
                rect.Width--;
                rect.Height--;
            }

            using (LinearGradientBrush brush = new LinearGradientBrush(
                       rect, Color.Transparent, Color.Transparent, mode))
            {
                Color[] colors = new Color[4];
                colors[0] = GetColor(baseColor, 0, 35, 24, 9);
                colors[1] = GetColor(baseColor, 0, 13, 8, 3);
                colors[2] = baseColor;
                colors[3] = GetColor(baseColor, 0, 35, 24, 9);

                ColorBlend blend = new ColorBlend();
                blend.Positions           = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f };
                blend.Colors              = colors;
                brush.InterpolationColors = blend;
                if (style != RoundStyle.None)
                {
                    using (GraphicsPath path =
                               GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                    {
                        g.FillPath(brush, path);
                    }

                    if (drawGlass)
                    {
                        if (baseColor.A > 80)
                        {
                            Rectangle rectTop = rect;

                            if (mode == LinearGradientMode.Vertical)
                            {
                                rectTop.Height = (int)(rectTop.Height * basePosition);
                            }
                            else
                            {
                                rectTop.Width = (int)(rect.Width * basePosition);
                            }
                            using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath(
                                       rectTop, roundWidth, RoundStyle.Top, false))
                            {
                                using (SolidBrush brushAlpha =
                                           new SolidBrush(Color.FromArgb(128, 255, 255, 255)))
                                {
                                    g.FillPath(brushAlpha, pathTop);
                                }
                            }
                        }

                        RectangleF glassRect = rect;
                        if (mode == LinearGradientMode.Vertical)
                        {
                            glassRect.Y      = rect.Y + rect.Height * basePosition;
                            glassRect.Height = (rect.Height - rect.Height * basePosition) * 2;
                        }
                        else
                        {
                            glassRect.X     = rect.X + rect.Width * basePosition;
                            glassRect.Width = (rect.Width - rect.Width * basePosition) * 2;
                        }
                        ControlPaintEx.DrawGlass(g, glassRect, 170, 0);
                    }

                    if (drawBorder)
                    {
                        using (GraphicsPath path =
                                   GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                        {
                            using (Pen pen = new Pen(borderColor))
                            {
                                g.DrawPath(pen, path);
                            }
                        }

                        rect.Inflate(-1, -1);
                        using (GraphicsPath path =
                                   GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                        {
                            using (Pen pen = new Pen(innerBorderColor))
                            {
                                g.DrawPath(pen, path);
                            }
                        }
                    }
                }
                else
                {
                    g.FillRectangle(brush, rect);

                    if (drawGlass)
                    {
                        if (baseColor.A > 80)
                        {
                            Rectangle rectTop = rect;
                            if (mode == LinearGradientMode.Vertical)
                            {
                                rectTop.Height = (int)(rectTop.Height * basePosition);
                            }
                            else
                            {
                                rectTop.Width = (int)(rect.Width * basePosition);
                            }
                            using (SolidBrush brushAlpha =
                                       new SolidBrush(Color.FromArgb(128, 255, 255, 255)))
                            {
                                g.FillRectangle(brushAlpha, rectTop);
                            }
                        }

                        RectangleF glassRect = rect;
                        if (mode == LinearGradientMode.Vertical)
                        {
                            glassRect.Y      = rect.Y + rect.Height * basePosition;
                            glassRect.Height = (rect.Height - rect.Height * basePosition) * 2;
                        }
                        else
                        {
                            glassRect.X     = rect.X + rect.Width * basePosition;
                            glassRect.Width = (rect.Width - rect.Width * basePosition) * 2;
                        }
                        ControlPaintEx.DrawGlass(g, glassRect, 200, 0);
                    }

                    if (drawBorder)
                    {
                        using (Pen pen = new Pen(borderColor))
                        {
                            g.DrawRectangle(pen, rect);
                        }

                        rect.Inflate(-1, -1);
                        using (Pen pen = new Pen(innerBorderColor))
                        {
                            g.DrawRectangle(pen, rect);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        {
            ToolStrip       toolStrip = e.ToolStrip;
            ToolStripButton item      = e.Item as ToolStripButton;
            Graphics        graphics  = e.Graphics;

            if (item == null)
            {
                return;
            }
            LinearGradientMode    mode      = (toolStrip.Orientation == Orientation.Horizontal) ? LinearGradientMode.Vertical : LinearGradientMode.Horizontal;
            SmoothingModeGraphics graphics2 = new SmoothingModeGraphics(graphics);
            Rectangle             bounds    = new Rectangle(Point.Empty, item.Size);

            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.CheckState == CheckState.Unchecked)
            {
                if (item.Selected)
                {
                    Bitmap img = item.Pressed ? ((Bitmap)this.ColorTable.BaseItemDown) : ((Bitmap)this.ColorTable.BaseItemMouse);
                    if (img != null)
                    {
                        ImageDrawRect.DrawRect(graphics, img, bounds, Rectangle.FromLTRB(this.ColorTable.BackRectangle.X, this.ColorTable.BackRectangle.Y, this.ColorTable.BackRectangle.Width, this.ColorTable.BackRectangle.Height), 1, 1);
                    }
                    else
                    {
                        Color baseItemHover = this.ColorTable.BaseItemHover;
                        if (item.Pressed)
                        {
                            baseItemHover = this.ColorTable.BaseItemPressed;
                        }
                        RenderHelperStrip.RenderBackgroundInternal(graphics, bounds, baseItemHover, this.ColorTable.BaseItemBorder, this.ColorTable.Back, this.ColorTable.BaseItemRadiusStyle, this.ColorTable.BaseItemRadius, this.ColorTable.BaseItemBorderShow, this.ColorTable.BaseItemAnamorphosis, mode);
                    }
                    goto Label_0302;
                }
                if (!(toolStrip is ToolStripOverflow))
                {
                    goto Label_0302;
                }
                using (Brush brush = new SolidBrush(this.ColorTable.ItemHover))
                {
                    graphics.FillRectangle(brush, bounds);
                    goto Label_0302;
                }
            }
            Bitmap baseItemMouse = (Bitmap)this.ColorTable.BaseItemMouse;
            Color  baseColor     = ControlPaint.Light(this.ColorTable.ItemHover);

            if (item.Selected)
            {
                baseColor     = this.ColorTable.ItemHover;
                baseItemMouse = (Bitmap)this.ColorTable.BaseItemMouse;
            }
            if (item.Pressed)
            {
                baseColor     = this.ColorTable.ItemPressed;
                baseItemMouse = (Bitmap)this.ColorTable.BaseItemDown;
            }
            if (baseItemMouse == null)
            {
                RenderHelperStrip.RenderBackgroundInternal(graphics, bounds, baseColor, this.ColorTable.BaseItemBorder, this.ColorTable.Back, this.ColorTable.BaseItemRadiusStyle, this.ColorTable.BaseItemRadius, this.ColorTable.BaseItemBorderShow, this.ColorTable.BaseItemAnamorphosis, mode);
            }
            else
            {
                ImageDrawRect.DrawRect(graphics, baseItemMouse, bounds, Rectangle.FromLTRB(this.ColorTable.BackRectangle.X, this.ColorTable.BackRectangle.Y, this.ColorTable.BackRectangle.Width, this.ColorTable.BackRectangle.Height), 1, 1);
            }
Label_0302:
            graphics2.Dispose();
        }
Ejemplo n.º 5
0
        protected override void OnRenderItemCheck(

            ToolStripItemImageRenderEventArgs e)

        {

            ToolStrip toolStrip = e.ToolStrip;

            Graphics g = e.Graphics;



            if (toolStrip is ToolStripDropDown &&

               e.Item is ToolStripMenuItem)

            {

                bool bDrawLogo = NeedDrawLogo(toolStrip);

                int offsetMargin = bDrawLogo ? OffsetMargin : 0;

                Rectangle rect = e.ImageRectangle;



                if (e.Item.RightToLeft == RightToLeft.Yes)

                {

                    rect.X -= offsetMargin + 2;

                }

                else

                {

                    rect.X += offsetMargin + 2;

                }



                rect.Width = 13;

                rect.Y += 1;

                rect.Height -= 3;



                using (SmoothingModeGraphics sg = new SmoothingModeGraphics(g))

                {

                    using (GraphicsPath path = new GraphicsPath())

                    {

                        path.AddRectangle(rect);

                        using (PathGradientBrush brush = new PathGradientBrush(path))

                        {

                            brush.CenterColor = Color.White;

                            brush.SurroundColors = new Color[] { ControlPaint.Light(ColorTable.BackNormal) };

                            Blend blend = new Blend();

                            blend.Positions = new float[] { 0f, 0.3f, 1f };

                            blend.Factors = new float[] { 0f, 0.5f, 1f };

                            brush.Blend = blend;

                            g.FillRectangle(brush, rect);

                        }

                    }



                    using (Pen pen = new Pen(ControlPaint.Light(ColorTable.BackNormal)))

                    {

                        g.DrawRectangle(pen, rect);

                    }



                    ControlPaintEx.DrawCheckedFlag(g, rect, ColorTable.Fore);

                }

            }

            else

            {

                base.OnRenderItemCheck(e);

            }

        }
Ejemplo n.º 6
0
        protected override void OnRenderButtonBackground(
            ToolStripItemRenderEventArgs e)
        {
            ToolStripButton item = e.Item as ToolStripButton;

            if (item != null)
            {
                LinearGradientMode mode =
                    e.ToolStrip.Orientation == Orientation.Horizontal ?
                    LinearGradientMode.Vertical : LinearGradientMode.Horizontal;
                Graphics g = e.Graphics;
                g.SmoothingMode = SmoothingMode.AntiAlias;
                Rectangle bounds = new Rectangle(Point.Empty, item.Size);

                if (item.BackgroundImage != null)
                {
                    Rectangle clipRect = item.Selected ? item.ContentRectangle : bounds;
                    ControlPaintEx.DrawBackgroundImage(
                        g,
                        item.BackgroundImage,
                        ColorTable.BackColorNormal,
                        item.BackgroundImageLayout,
                        bounds,
                        clipRect);
                }

                if (item.CheckState == CheckState.Unchecked)
                {
                    if (item.Selected)
                    {
                        Color color = ColorTable.BackColorHover;
                        if (item.Pressed)
                        {
                            color = ColorTable.BackColorPressed;
                        }
                        RenderBackgroundInternal(
                            g,
                            bounds,
                            color,
                            ColorTable.BorderColor,
                            ColorTable.BackColorNormal,
                            RoundStyle.All,
                            true,
                            true,
                            mode);
                        return;
                    }
                    else
                    {
                        if (e.ToolStrip is ToolStripOverflow)
                        {
                            using (Brush brush = new SolidBrush(ColorTable.BackColorNormal))
                            {
                                g.FillRectangle(brush, bounds);
                            }
                            return;
                        }
                    }
                }
                else
                {
                    Color color = ControlPaint.Light(ColorTable.BackColorHover);
                    if (item.Selected)
                    {
                        color = ColorTable.BackColorHover;
                    }
                    if (item.Pressed)
                    {
                        color = ColorTable.BackColorPressed;
                    }
                    RenderBackgroundInternal(
                        e.Graphics,
                        bounds,
                        color,
                        ColorTable.BorderColor,
                        ColorTable.BackColorNormal,
                        RoundStyle.All,
                        true,
                        true,
                        mode);
                    return;
                }
            }

            base.OnRenderButtonBackground(e);
        }
Ejemplo n.º 7
0
 public static void RenderBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, int roundWidth, float basePosition, bool drawBorder, bool drawGlass, LinearGradientMode mode)
 {
     if (drawBorder)
     {
         rect.Width--;
         rect.Height--;
     }
     using (LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode))
     {
         Color[]    colorArray = new Color[] { GetColor(baseColor, 0, 0x23, 0x18, 9), GetColor(baseColor, 0, 13, 8, 3), baseColor, GetColor(baseColor, 0, 0x23, 0x18, 9) };
         ColorBlend blend      = new ColorBlend();
         float[]    numArray   = new float[4];
         numArray[1]               = basePosition;
         numArray[2]               = basePosition + 0.05f;
         numArray[3]               = 1f;
         blend.Positions           = numArray;
         blend.Colors              = colorArray;
         brush.InterpolationColors = blend;
         if (style != RoundStyle.None)
         {
             using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
             {
                 g.FillPath(brush, path);
             }
             if (drawGlass)
             {
                 if (baseColor.A > 80)
                 {
                     Rectangle rectangle = rect;
                     if (mode == LinearGradientMode.Vertical)
                     {
                         rectangle.Height = (int)(rectangle.Height * basePosition);
                     }
                     else
                     {
                         rectangle.Width = (int)(rect.Width * basePosition);
                     }
                     using (GraphicsPath path2 = GraphicsPathHelper.CreatePath(rectangle, roundWidth, RoundStyle.Top, false))
                     {
                         using (SolidBrush brush2 = new SolidBrush(Color.FromArgb(0x80, 0xff, 0xff, 0xff)))
                         {
                             g.FillPath(brush2, path2);
                         }
                     }
                 }
                 RectangleF glassRect = rect;
                 if (mode == LinearGradientMode.Vertical)
                 {
                     glassRect.Y      = rect.Y + (rect.Height * basePosition);
                     glassRect.Height = (rect.Height - (rect.Height * basePosition)) * 2f;
                 }
                 else
                 {
                     glassRect.X     = rect.X + (rect.Width * basePosition);
                     glassRect.Width = (rect.Width - (rect.Width * basePosition)) * 2f;
                 }
                 ControlPaintEx.DrawGlass(g, glassRect, 170, 0);
             }
             if (!drawBorder)
             {
                 return;
             }
             using (GraphicsPath path3 = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
             {
                 using (Pen pen = new Pen(borderColor))
                 {
                     g.DrawPath(pen, path3);
                 }
             }
             rect.Inflate(-1, -1);
             using (GraphicsPath path4 = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
             {
                 using (Pen pen2 = new Pen(innerBorderColor))
                 {
                     g.DrawPath(pen2, path4);
                 }
                 return;
             }
         }
         g.FillRectangle(brush, rect);
         if (drawGlass)
         {
             if (baseColor.A > 80)
             {
                 Rectangle rectangle2 = rect;
                 if (mode == LinearGradientMode.Vertical)
                 {
                     rectangle2.Height = (int)(rectangle2.Height * basePosition);
                 }
                 else
                 {
                     rectangle2.Width = (int)(rect.Width * basePosition);
                 }
                 using (SolidBrush brush3 = new SolidBrush(Color.FromArgb(0x80, 0xff, 0xff, 0xff)))
                 {
                     g.FillRectangle(brush3, rectangle2);
                 }
             }
             RectangleF ef2 = rect;
             if (mode == LinearGradientMode.Vertical)
             {
                 ef2.Y      = rect.Y + (rect.Height * basePosition);
                 ef2.Height = (rect.Height - (rect.Height * basePosition)) * 2f;
             }
             else
             {
                 ef2.X     = rect.X + (rect.Width * basePosition);
                 ef2.Width = (rect.Width - (rect.Width * basePosition)) * 2f;
             }
             ControlPaintEx.DrawGlass(g, ef2, 200, 0);
         }
         if (drawBorder)
         {
             using (Pen pen3 = new Pen(borderColor))
             {
                 g.DrawRectangle(pen3, rect);
             }
             rect.Inflate(-1, -1);
             using (Pen pen4 = new Pen(innerBorderColor))
             {
                 g.DrawRectangle(pen4, rect);
             }
         }
     }
 }
Ejemplo n.º 8
0
        protected virtual void WmNcPaint(ref Message m)
        {
            IntPtr hDC = Win32.NativeMethods.GetWindowDC(m.HWnd);

            if (hDC == IntPtr.Zero)
            {
                return;
            }

            try
            {
                Rectangle bounds = new Rectangle(Point.Empty, base.Size);
                Rectangle client = base.ClientRectangle;
                client.X = _borderWidth;
                client.Y = _borderWidth;

                using (ImageDc bufferedDC = new ImageDc(base.Width, base.Height))
                {
                    Win32.NativeMethods.ExcludeClipRect(
                        bufferedDC.Hdc,
                        client.Left,
                        client.Top,
                        client.Right,
                        client.Bottom);

                    DrawTransparentBackground(
                        bufferedDC.Hdc,
                        bounds,
                        base.Location);

                    using (Graphics g = Graphics.FromHdc(bufferedDC.Hdc))
                    {
                        using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                                   bounds, _radius, _roundStyle, true))
                        {
                            g.SetClip(path);
                        }
                        g.ExcludeClip(client);

                        if (base.BackgroundImage != null)
                        {
                            ControlPaintEx.DrawBackgroundImage(
                                g,
                                base.BackgroundImage,
                                base.BackColor,
                                base.BackgroundImageLayout,
                                bounds,
                                bounds);
                        }
                        else if (base.BackColor != Color.Transparent)
                        {
                            using (Brush brush = new SolidBrush(base.BackColor))
                            {
                                g.FillRectangle(brush, bounds);
                            }
                        }

                        g.ResetClip();

                        using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                                   bounds, _radius, _roundStyle, true))
                        {
                            using (SmoothingModeGraphics antiGraphics = new SmoothingModeGraphics(g))
                            {
                                g.DrawPath(Pens.Black, path);
                            }
                        }
                    }

                    Win32.NativeMethods.ExcludeClipRect(
                        hDC,
                        client.Left,
                        client.Top,
                        client.Right,
                        client.Bottom);

                    Win32.NativeMethods.BitBlt(
                        hDC,
                        bounds.X,
                        bounds.Y,
                        bounds.Width,
                        bounds.Height,
                        bufferedDC.Hdc,
                        0,
                        0,
                        TernaryRasterOperations.SRCCOPY);
                }
            }
            catch
            {
            }
            finally
            {
                Win32.NativeMethods.ReleaseDC(m.HWnd, hDC);
            }
        }
Ejemplo n.º 9
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            if (base.BackgroundImage != null)
            {
                Graphics  g          = e.Graphics;
                Rectangle bounds     = new Rectangle(Point.Empty, base.Size);
                Rectangle clientRect = base.ClientRectangle;

                WINDOWINFO info   = GetWindowInfo();
                Point      offset = new Point(
                    info.rcClient.Left - info.rcWindow.Left,
                    info.rcClient.Top - info.rcWindow.Top);

                IntPtr hDC = g.GetHdc();

                try
                {
                    using (ImageDc imageDc = new ImageDc(bounds.Width, bounds.Height))
                    {
                        using (Graphics gDc = Graphics.FromHdc(imageDc.Hdc))
                        {
                            ControlPaintEx.DrawBackgroundImage(
                                gDc,
                                base.BackgroundImage,
                                base.BackColor,
                                base.BackgroundImageLayout,
                                bounds,
                                bounds);
                        }

                        Win32.NativeMethods.BitBlt(
                            hDC,
                            clientRect.X,
                            clientRect.Y,
                            clientRect.Width,
                            clientRect.Height,
                            imageDc.Hdc,
                            offset.X,
                            offset.Y,
                            TernaryRasterOperations.SRCCOPY);
                    }
                }
                catch
                {
                }
                finally
                {
                    g.ReleaseHdc(hDC);
                }
                return;
            }

            if (base.BackColor == Color.Transparent)
            {
                Graphics g   = e.Graphics;
                IntPtr   hDC = g.GetHdc();

                try
                {
                    WINDOWINFO info   = GetWindowInfo();
                    Point      offset = new Point(
                        info.rcClient.Left - info.rcWindow.Left,
                        info.rcClient.Top - info.rcWindow.Top);

                    offset += (Size)base.Location;

                    DrawTransparentBackground(
                        hDC,
                        base.ClientRectangle,
                        offset);
                }
                catch
                {
                }
                finally
                {
                    g.ReleaseHdc(hDC);
                }
                return;
            }

            base.OnPaintBackground(e);
        }