Exemplo n.º 1
0
        internal 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--;
            }

            if (rect.Width == 0 || rect.Height == 0)
            {
                return;
            }

            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 (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);
                            }
                        }
                    }

                    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;
                        }
                        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 (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);
                        }
                    }

                    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;
                        }
                        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);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected virtual void OnRenderThumb(PaintThumbEventArgs e)
        {
            Graphics            g         = e.Graphics;
            Rectangle           rect      = e.ClipRectangle;
            ControlState        state     = e.ControlState;
            ThumbArrowDirection direction = ThumbArrowDirection.None;
            Color begin  = ColorTable.ThumbBackNormal;
            Color end    = ColorTable.TrackInnerBorder;
            Color border = ColorTable.ThumbBorderNormal;
            float mode   =
                base.Orientation == Orientation.Horizontal ?
                90f : 0f;

            switch (base.Orientation)
            {
            case Orientation.Horizontal:
                switch (base.TickStyle)
                {
                case TickStyle.None:
                case TickStyle.BottomRight:
                    direction = ThumbArrowDirection.Down;
                    break;

                case TickStyle.TopLeft:
                    direction = ThumbArrowDirection.Up;
                    break;

                case TickStyle.Both:
                    direction = ThumbArrowDirection.None;
                    break;
                }
                break;

            case Orientation.Vertical:
                switch (base.TickStyle)
                {
                case TickStyle.TopLeft:
                    direction = ThumbArrowDirection.Left;
                    break;

                case TickStyle.None:
                case TickStyle.BottomRight:
                    direction = ThumbArrowDirection.Right;
                    break;

                case TickStyle.Both:
                    direction = ThumbArrowDirection.None;
                    break;
                }
                break;
            }

            switch (state)
            {
            case ControlState.Hover:
                begin  = ColorTable.ThumbBackHover;
                border = ColorTable.ThumbBorderHover;
                break;
            }

            using (SmoothingModeGraphics sg = new SmoothingModeGraphics(g))
            {
                using (GraphicsPath path =
                           GraphicsPathHelper.CreateTrackBarThumbPath(
                               rect, direction))
                {
                    using (LinearGradientBrush brush = new LinearGradientBrush(
                               rect, begin, end, mode))
                    {
                        Blend blend = new Blend();
                        blend.Positions = new float[] { 0, .2f, .5f, .8f, 1f };
                        blend.Factors   = new float[] { 1f, .7f, 0, .7f, 1f };
                        brush.Blend     = blend;

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

                rect.Inflate(-1, -1);
                using (GraphicsPath path =
                           GraphicsPathHelper.CreateTrackBarThumbPath(
                               rect, direction))
                {
                    using (Pen pen = new Pen(ColorTable.TrackInnerBorder))
                    {
                        g.DrawPath(pen, path);
                    }
                }
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
                     }
                 }
             }
         }
     }
 }