Beispiel #1
0
        protected virtual void PaintButtonBackground(FluidPaintEventArgs e)
        {
            const int const_radius = 8;

            if (this.shape != ButtonShape.Flat || IsDown)
            {
                Rectangle rect = ButtonRectangle;
                rect.Width--;
                rect.Height--;
                if (rect.Width < 1 || rect.Height < 1)
                {
                    return;
                }

                rect.Offset(e.ControlBounds.X, e.ControlBounds.Y);

                Graphics g = e.Graphics;

                int radius = e.ScaleX(const_radius);
                if (radius > rect.Width / 2) radius = rect.Width / 2;

                Color endColor = this.BackColor;
                if (!Enabled)
                {
                    endColor = ColorConverter.AlphaBlendColor(Color.Black, endColor, 128);
                }
                int alpha = Enabled ? 127 : 32;
                Color startColor = ColorConverter.AlphaBlendColor(endColor, Color.White, alpha);  //Color.FromArgb(0x7fffffff);
                Color borderColor = ColorConverter.AlphaBlendColor(endColor, Color.White, 100);

                GraphicShape shape = ButtonShapeToGraphic(this.shape);
                using (GraphicsPlus gp = new GraphicsPlus(g))
                {
                    if (GradientFill)
                    {
                        GraphicsPlus.GradientMode mode = IsDown ? GraphicsPlus.GradientMode.Bottom : GraphicsPlus.GradientMode.Top;
                        gp.GradientFillShape(rect, radius, startColor, endColor, mode, shape, corners);
                        using (PenPlus pen = new PenPlus(borderColor, (float)1))
                        {
                            gp.DrawShape(rect, radius, pen, shape, corners);
                        }
                    }
                    else
                    {
                        if (IsDown)
                        {
                            endColor = ColorConverter.AlphaBlendColor(endColor, endColor, 128);
                        }
                        gp.GradientFillShape(rect, radius, endColor, endColor, GraphicsPlus.GradientMode.Bottom, shape, corners);
                        using (PenPlus pen = new PenPlus(borderColor, (float)1))
                        {
                            gp.DrawShape(rect, radius, pen, shape, corners);
                        }
                    }
                }
            }
            PerformPaintButtonContent(e);
        }