Example #1
0
        public static void DrawRoundRectBorder(Graphics g, Control ctrl, Rectangle rect, int roundCornerDepth, int borderSize, Color borderColor, Color gradientStartColor, Color gradientEndColor, LinearGradientMode gradientDirection, bool bgOpaque)
        {
            roundCornerDepth = 0; //--ak:temp:

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

            ctrl.BackColor = Color.Transparent; //== THIS AFFECTS LABLE ETC.'S BG.
            ///
            if (bgOpaque == true)
            {
                g.FillRectangle(new SolidBrush(borderColor), rect); //==DRAW OPAQUE BG.
            }

            GraphicsPath graphPath = XPanelUtil.GetRoundPath(rect, roundCornerDepth, borderSize);

            //== Draw Background ==
            LinearGradientBrush brush = new LinearGradientBrush(rect,
                                                                gradientStartColor,
                                                                gradientEndColor,
                                                                gradientDirection);

            //SolidBrush brush2 = new SolidBrush(gradientStartColor);
            //TextureBrush brush3 = new TextureBrush(Image.FromFile(@"D:\PROJECTS\Backups\bg3.bmp"));
            g.FillPath(brush, graphPath);

            //== Draw Border ==
            g.DrawPath(new Pen(borderColor, borderSize), graphPath);
        }
Example #2
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
            ///
            int tmpShadowOffSet      = Math.Min(Math.Min(_shadowOffSet, this.Width - 2), this.Height - 2);
            int tmpRoundCornerRadius = 0; //--ak:temp: Math.Min(Math.Min(_roundCornerRadius, this.Width - 2), this.Height - 2);

            Rectangle rect       = new Rectangle(0, 0, this.Width - tmpShadowOffSet - 1, this.Height - tmpShadowOffSet - 1);
            Rectangle rectShadow = new Rectangle(tmpShadowOffSet, tmpShadowOffSet, this.Width - tmpShadowOffSet - 1, this.Height - tmpShadowOffSet - 1);

            GraphicsPath graphPathShadow = null;
            GraphicsPath graphPath       = null;

            if (tmpRoundCornerRadius >= 1)
            {
                if (this.Width > 1 && this.Height > 1)
                {
                    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                    if (_roundCornerSide == SideEnum.Top)
                    {
                        graphPathShadow = XPanelUtil.GetRoundPathXTop(rectShadow, tmpRoundCornerRadius);
                        graphPath       = XPanelUtil.GetRoundPathXTop(rect, tmpRoundCornerRadius);
                    }
                    else if (_roundCornerSide == SideEnum.Left)
                    {
                        graphPathShadow = XPanelUtil.GetRoundPathXLeft(rectShadow, tmpRoundCornerRadius);
                        graphPath       = XPanelUtil.GetRoundPathXLeft(rect, tmpRoundCornerRadius);
                    }
                    else if (_roundCornerSide == SideEnum.Bottom)
                    {
                        graphPathShadow = XPanelUtil.GetRoundPathXTop(rectShadow, tmpRoundCornerRadius);
                        graphPath       = XPanelUtil.GetRoundPathXTop(rect, tmpRoundCornerRadius);
                    }
                    else if (_roundCornerSide == SideEnum.Right)
                    {
                        graphPathShadow = XPanelUtil.GetRoundPathXLeft(rectShadow, tmpRoundCornerRadius);
                        graphPath       = XPanelUtil.GetRoundPathXLeft(rect, tmpRoundCornerRadius);
                    }
                }
            }
            else
            {
                graphPath = new GraphicsPath();
                graphPath.AddRectangle(rect);

                graphPath = new GraphicsPath();
                graphPath.AddRectangle(rectShadow);
            }

            //== Draw Shadow ==
            if (tmpShadowOffSet > 0)
            {
                using (PathGradientBrush gBrush = new PathGradientBrush(graphPathShadow))
                {
                    gBrush.WrapMode = WrapMode.Clamp;
                    ColorBlend colorBlend = new ColorBlend(3);
                    colorBlend.Colors = new Color[] { Color.Transparent,
                                                      Color.FromArgb(180, this._shadowColor),
                                                      Color.FromArgb(180, this._shadowColor) };

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

                    gBrush.InterpolationColors = colorBlend;
                    e.Graphics.FillPath(gBrush, graphPathShadow);
                }
            }

            //== Draw Background ==
            if (_drawGradient == true)
            {
                //////LinearGradientBrush brush = new LinearGradientBrush(rect,
                //////    this._gradientStartColor,
                //////    this._gradientEndColor,
                //////    this._gradientDirection);
                SolidBrush brush = new SolidBrush(this._gradientStartColor);
                //TextureBrush brush3 = new TextureBrush(Image.FromFile(@"D:\PROJECTS\Backups\bg3.bmp"));
                e.Graphics.FillPath(brush, graphPath);
            }
            else
            {
            }

            //== Draw Border ==
            if (this._borderWidth != 0)
            {
                e.Graphics.DrawPath(new Pen(Color.FromArgb(180, this._borderColor), _borderWidth), graphPath);
            }

            //== Draw Logo Image ==
            if (_image != null)
            {
                e.Graphics.DrawImageUnscaled(_image, _imageLocation);
            }
        }