Ejemplo n.º 1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics g = e.Graphics;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                       ClientRectangle, 8, RoundStyle.All, false))
            {
                using (SolidBrush brush = new SolidBrush(ColorTable.BackColorNormal))
                {
                    g.FillPath(brush, path);
                }
                using (Pen pen = new Pen(ColorTable.BorderColor))
                {
                    g.DrawPath(pen, path);

                    using (GraphicsPath innerPath = GraphicsPathHelper.CreatePath(
                               ClientRectangle, 8, RoundStyle.All, true))
                    {
                        g.DrawPath(pen, innerPath);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public static void CreateRegion(Control control, Rectangle rect)
 {
     using (GraphicsPath path =
                GraphicsPathHelper.CreatePath(rect, 8, RoundStyle.All, false))
     {
         if (control.Region != null)
         {
             control.Region.Dispose();
         }
         control.Region = new Region(path);
     }
 }
Ejemplo n.º 3
0
 private void SetRegion()
 {
     using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                ClientRectangle, 8, RoundStyle.All, false))
     {
         if (base.Region != null)
         {
             base.Region.Dispose();
         }
         base.Region = new Region(path);
     }
 }
Ejemplo n.º 4
0
        protected virtual void OnRenderTrack(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            if (BackgroundImage != null)
            {
                g.DrawImage(BackgroundImage, e.ClipRectangle);
                return;
            }

            Rectangle rect       = e.ClipRectangle;
            bool      horizontal = base.Orientation == Orientation.Horizontal;
            float     mode       = horizontal ? 0f : 270f;

            if (horizontal)
            {
                rect.Inflate(0, 1);
            }
            else
            {
                rect.Inflate(1, 0);
            }

            SmoothingModeGraphics sg = new SmoothingModeGraphics(g);

            using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                       rect, 4, RoundStyle.All, true))
            {
                using (LinearGradientBrush brush = new LinearGradientBrush(
                           rect, ColorTable.TrackBegin, ColorTable.TrackEnd, mode))
                {
                    g.FillPath(brush, path);
                }

                using (Pen pen = new Pen(ColorTable.TrackBorder))
                {
                    g.DrawPath(pen, path);
                }
            }

            rect.Inflate(-1, -1);
            using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                       rect, 4, RoundStyle.All, true))
            {
                using (Pen pen = new Pen(ColorTable.TrackInnerBorder))
                {
                    g.DrawPath(pen, path);
                }
            }

            sg.Dispose();
        }
Ejemplo n.º 5
0
        public override Region CreateRegion(SkinForm form)
        {
            Rectangle rect = new Rectangle(Point.Empty, form.Size);

            using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                       rect,
                       form.Radius,
                       form.RoundStyle,
                       false))
            {
                return(new Region(path));
            }
        }
Ejemplo n.º 6
0
        protected override void OnRenderToolStripBackground(
            ToolStripRenderEventArgs e)
        {
            Color     baseColor = ColorTable.BackColorNormal;
            ToolStrip toolStrip = e.ToolStrip;
            Graphics  g         = e.Graphics;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            if (toolStrip is ToolStripDropDown)
            {
                RegionHelper.CreateRegion(e.ToolStrip, e.AffectedBounds);

                Rectangle rect = e.AffectedBounds;

                using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                           rect, 8, RoundStyle.All, false))
                {
                    using (SolidBrush brush = new SolidBrush(ColorTable.BackColorNormal))
                    {
                        g.FillPath(brush, path);
                    }
                    using (Pen pen = new Pen(ColorTable.BorderColor))
                    {
                        g.DrawPath(pen, path);

                        using (GraphicsPath innerPath = GraphicsPathHelper.CreatePath(
                                   rect, 8, RoundStyle.All, true))
                        {
                            g.DrawPath(pen, innerPath);
                        }
                    }
                }
            }
            else
            {
                LinearGradientMode mode =
                    e.ToolStrip.Orientation == Orientation.Horizontal ?
                    LinearGradientMode.Vertical : LinearGradientMode.Horizontal;
                RenderBackgroundInternal(
                    g,
                    e.AffectedBounds,
                    ColorTable.BackColorHover,
                    ColorTable.BorderColor,
                    ColorTable.BackColorNormal,
                    RoundStyle.All,
                    false,
                    true,
                    mode);
            }
        }
Ejemplo n.º 7
0
        internal static void DrawGradientRoundRect(
            Graphics g,
            Rectangle rect,
            Color begin,
            Color end,
            Color border,
            Color innerBorder,
            Blend blend,
            LinearGradientMode mode,
            int radios,
            RoundStyle roundStyle,
            bool drawBorder,
            bool drawInnderBorder)
        {
            using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                       rect, radios, roundStyle, true))
            {
                using (LinearGradientBrush brush = new LinearGradientBrush(
                           rect, begin, end, mode))
                {
                    brush.Blend = blend;
                    g.FillPath(brush, path);
                }

                if (drawBorder)
                {
                    using (Pen pen = new Pen(border))
                    {
                        g.DrawPath(pen, path);
                    }
                }
            }

            if (drawInnderBorder)
            {
                rect.Inflate(-1, -1);
                using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                           rect, radios, roundStyle, true))
                {
                    using (Pen pen = new Pen(innerBorder))
                    {
                        g.DrawPath(pen, path);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        protected override void OnRenderSkinFormBackground(
            SkinFormBackgroundRenderEventArgs e)
        {
            Graphics  g    = e.Graphics;
            Rectangle rect = e.ClipRectangle;
            SkinForm  form = e.SkinForm;

            using (AntiAliasGraphics antiGraphics = new AntiAliasGraphics(g))
            {
                using (Brush brush = new SolidBrush(ColorTable.Back))
                {
                    using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                               rect, form.Radius, form.RoundStyle, false))
                    {
                        g.FillPath(brush, path);
                    }
                }
            }
        }
Ejemplo n.º 9
0
 public static void CreateRegion(
     Control control,
     Rectangle bounds,
     int radius,
     RoundStyle roundStyle)
 {
     using (GraphicsPath path =
                GraphicsPathHelper.CreatePath(
                    bounds, radius, roundStyle, true))
     {
         Region region = new Region(path);
         path.Widen(Pens.White);
         region.Union(path);
         if (control.Region != null)
         {
             control.Region.Dispose();
         }
         control.Region = region;
     }
 }
Ejemplo n.º 10
0
        private void DrawBorder(
            Graphics g, Rectangle rect, RoundStyle roundStyle, int radius)
        {
            rect.Width  -= 1;
            rect.Height -= 1;
            using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                       rect, radius, roundStyle, false))
            {
                using (Pen pen = new Pen(ColorTable.Border))
                {
                    g.DrawPath(pen, path);
                }
            }

            rect.Inflate(-1, -1);
            using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                       rect, radius, roundStyle, false))
            {
                using (Pen pen = new Pen(ColorTable.InnerBorder))
                {
                    g.DrawPath(pen, path);
                }
            }
        }
Ejemplo n.º 11
0
        internal 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, 68, 69, 54);

                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 (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(80, 255, 255, 255)))
                            {
                                g.FillPath(brushAlpha, pathTop);
                            }
                        }
                    }

                    //if (drawGlass)
                    //{
                    //    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;
                    //    }
                    //    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 (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(80, 255, 255, 255)))
                        {
                            g.FillRectangle(brushAlpha, rectTop);
                        }
                    }

                    if (drawGlass)
                    {
                        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;
                        }
                        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.º 12
0
        protected override void OnRenderImageMargin(
            ToolStripRenderEventArgs e)
        {
            if (e.ToolStrip is ToolStripDropDownMenu)
            {
                Rectangle rect = e.AffectedBounds;
                Graphics  g    = e.Graphics;
                rect.Width = OffsetMargin;
                if (e.ToolStrip.RightToLeft == RightToLeft.Yes)
                {
                    rect.X -= 2;
                }
                else
                {
                    rect.X += 2;
                }
                rect.Y         += 1;
                rect.Height    -= 2;
                g.SmoothingMode = SmoothingMode.AntiAlias;
                using (LinearGradientBrush brush = new LinearGradientBrush(
                           rect,
                           ColorTable.BackColorHover,
                           Color.White,
                           90f))
                {
                    Blend blend = new Blend();
                    blend.Positions = new float[] { 0f, .2f, 1f };
                    blend.Factors   = new float[] { 0f, 0.1f, .9f };
                    brush.Blend     = blend;
                    rect.Y         += 1;
                    rect.Height    -= 2;
                    using (GraphicsPath path =
                               GraphicsPathHelper.CreatePath(rect, 8, RoundStyle.All, false))
                    {
                        g.FillPath(brush, path);
                    }
                }

                g.TextRenderingHint = TextRenderingHint.AntiAlias;
                StringFormat sf   = new StringFormat(StringFormatFlags.NoWrap);
                Font         font = new Font(
                    e.ToolStrip.Font.FontFamily, 11, FontStyle.Bold);
                sf.Alignment     = StringAlignment.Near;
                sf.LineAlignment = StringAlignment.Center;
                sf.Trimming      = StringTrimming.EllipsisCharacter;

                g.TranslateTransform(rect.X, rect.Bottom);
                g.RotateTransform(270f);

                if (!string.IsNullOrEmpty(MenuLogoString))
                {
                    Rectangle newRect = new Rectangle(
                        rect.X, rect.Y, rect.Height, rect.Width);

                    using (Brush brush = new SolidBrush(ColorTable.ForeColor))
                    {
                        g.DrawString(
                            MenuLogoString,
                            font,
                            brush,
                            newRect,
                            sf);
                    }
                }

                g.ResetTransform();
                return;
            }

            base.OnRenderImageMargin(e);
        }
Ejemplo n.º 13
0
 internal void RenderBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, CSharpWin.RoundStyle style, int roundWidth, float basePosition, bool drawBorder, bool drawGlass, LinearGradientMode mode)
 {
     if (drawBorder)
     {
         rect.Width--;
         rect.Height--;
     }
     if ((rect.Width > 0) && (rect.Height > 0))
     {
         using (LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode))
         {
             Rectangle  rectTop;
             SolidBrush brushAlpha;
             RectangleF glassRect;
             Pen        pen;
             Color[]    colors = new Color[] { this.GetColor(baseColor, 0, 0x23, 0x18, 9), this.GetColor(baseColor, 0, 13, 8, 3), baseColor, this.GetColor(baseColor, 0, 0x44, 0x45, 0x36) };
             ColorBlend blend  = new ColorBlend();
             float[]    arrays = new float[4];
             arrays[1]                 = basePosition;
             arrays[2]                 = basePosition + 0.05f;
             arrays[3]                 = 1f;
             blend.Positions           = arrays;
             blend.Colors              = colors;
             brush.InterpolationColors = blend;
             if (style != CSharpWin.RoundStyle.None)
             {
                 GraphicsPath path;
                 using (path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                 {
                     g.FillPath(brush, path);
                 }
                 if (baseColor.A > 80)
                 {
                     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, CSharpWin.RoundStyle.Top, false))
                     {
                         using (brushAlpha = new SolidBrush(Color.FromArgb(80, 0xff, 0xff, 0xff)))
                         {
                             g.FillPath(brushAlpha, pathTop);
                         }
                     }
                 }
                 if (drawGlass)
                 {
                     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;
                     }
                     this.DrawGlass(g, glassRect, 170, 0);
                 }
                 if (drawBorder)
                 {
                     using (path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                     {
                         using (pen = new Pen(borderColor))
                         {
                             g.DrawPath(pen, path);
                         }
                     }
                     rect.Inflate(-1, -1);
                     using (path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                     {
                         using (pen = new Pen(innerBorderColor))
                         {
                             g.DrawPath(pen, path);
                         }
                     }
                 }
             }
             else
             {
                 g.FillRectangle(brush, rect);
                 if (baseColor.A > 80)
                 {
                     rectTop = rect;
                     if (mode == LinearGradientMode.Vertical)
                     {
                         rectTop.Height = (int)(rectTop.Height * basePosition);
                     }
                     else
                     {
                         rectTop.Width = (int)(rect.Width * basePosition);
                     }
                     using (brushAlpha = new SolidBrush(Color.FromArgb(80, 0xff, 0xff, 0xff)))
                     {
                         g.FillRectangle(brushAlpha, rectTop);
                     }
                 }
                 if (drawGlass)
                 {
                     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;
                     }
                     this.DrawGlass(g, glassRect, 200, 0);
                 }
                 if (drawBorder)
                 {
                     using (pen = new Pen(borderColor))
                     {
                         g.DrawRectangle(pen, rect);
                     }
                     rect.Inflate(-1, -1);
                     using (pen = new Pen(innerBorderColor))
                     {
                         g.DrawRectangle(pen, rect);
                     }
                 }
             }
         }
     }
 }