Example #1
0
        public static void CreateRegion(
            Control Control,
            Rectangle BoundsRect,
            int Radius,
            ToolStripRoundStyle RoundStyle)
        {
            using (GraphicsPath path = ToolStripGraphicsPathHelper.CreatePath(BoundsRect, 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;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="G"></param>
        /// <param name="Rect"></param>
        /// <param name="BaseColor"></param>
        /// <param name="BorderColor"></param>
        /// <param name="InnerBorderColor"></param>
        /// <param name="Style"></param>
        /// <param name="RoundWidth"></param>
        /// <param name="BasePosition"></param>
        /// <param name="DrawBorder"></param>
        /// <param name="DrawGlass"></param>
        /// <param name="Mode"></param>
        internal static void RenderBackgroundInternal(
            Graphics G,
            Rectangle Rect,
            Color BaseColor,
            Color BorderColor,
            Color InnerBorderColor,
            ToolStripRoundStyle 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 != ToolStripRoundStyle.None)
                {
                    using (GraphicsPath path = ToolStripGraphicsPathHelper.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 = ToolStripGraphicsPathHelper.CreatePath(rectTop, RoundWidth, ToolStripRoundStyle.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;
                        }
                        ToolStripControlPaintEx.DrawGlass(G, glassRect, 170, 0);
                    }

                    if (DrawBorder)
                    {
                        using (GraphicsPath path = ToolStripGraphicsPathHelper.CreatePath(Rect, RoundWidth, Style, false))
                        {
                            using (Pen pen = new Pen(BorderColor))
                            {
                                G.DrawPath(pen, path);
                            }
                        }

                        Rect.Inflate(-1, -1);

                        using (GraphicsPath path = ToolStripGraphicsPathHelper.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;
                        }
                        ToolStripControlPaintEx.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);
                        }
                    }
                }
            }
        }