Esempio n. 1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            //base.OnPaint( e );
            Graphics g = e.Graphics;
            //g.TextRenderingHint = TextRenderingHint.AntiAlias;

            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Center;
            sf.Alignment     = StringAlignment.Center;
            sf.FormatFlags   = StringFormatFlags.NoWrap;


            if (Parent != null && !backgroundPainted)
            {
                g.FillRectangle(new SolidBrush(Parent.BackColor), ClientRectangle);
                backgroundPainted = true;
            }

            Rectangle rect = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1);

            GraphicsPath path = null;

            switch (FigureType)
            {
            case FigureType.None:
                path = ExtendedForms.RoundedRect(rect, 0);
                break;

            case FigureType.Rounded:
                path = ExtendedForms.RoundedRect(rect, BorderRadius);
                break;

            case FigureType.Skewed:
                path = ExtendedForms.SkewedRect(rect, BorderSkew);
                break;

            default:
                path = ExtendedForms.RoundedRect(rect, 0);
                break;
            }


            g.SmoothingMode = SmoothingMode.HighQuality;

            if (_isSelected && !_isPushed)
            {
                g.FillPath(new SolidBrush(SelectedColor.SetAlpha(_manager.CurrentValue)), path);
                g.DrawPath(new Pen(SelectedBorderColor), path);

                g.SmoothingMode = SmoothingMode.HighSpeed;

                g.DrawString(Text, Font, new SolidBrush(SelectedForeColor), rect, sf);
            }
            else if (_isSelected && _isPushed)
            {
                g.FillPath(new SolidBrush(SelectedColor.Darken(10)), path);
                g.DrawPath(new Pen(SelectedBorderColor.Darken(10)), path);

                g.SmoothingMode = SmoothingMode.HighSpeed;

                rect.Offset(0, 2);
                g.DrawString(Text, Font, new SolidBrush(SelectedForeColor), rect, sf);
            }
            else
            {
                g.FillPath(new SolidBrush(BackColor.SetAlpha(_manager.CurrentValue)), path);
                g.DrawPath(new Pen(BorderColor), path);

                g.SmoothingMode = SmoothingMode.HighSpeed;

                g.DrawString(Text, Font, new SolidBrush(ForeColor), rect, sf);
            }
        }
Esempio n. 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            StringFormat sf = new StringFormat {
                LineAlignment = StringAlignment.Center,
                Alignment     = StringAlignment.Center,
                FormatFlags   = StringFormatFlags.NoWrap
            };

            if (Parent != null && FigureType != FigureType.None)
            {
                g.FillRectangle(new SolidBrush(Parent.BackColor), ClientRectangle);
            }

            Rectangle rect;

            if (DrawBorder)
            {
                rect = new Rectangle(
                    ClientRectangle.X,
                    ClientRectangle.Y,
                    ClientRectangle.Width - 1,
                    ClientRectangle.Height - 1);
            }
            else
            {
                rect = ClientRectangle;
            }

            GraphicsPath path = null;

            switch (FigureType)
            {
            case FigureType.None:
                path = ExtendedForms.RoundedRect(rect, 0);
                break;

            case FigureType.Rounded:
                path = ExtendedForms.RoundedRect(rect, BorderRadius);
                break;

            case FigureType.Skewed:
                path = ExtendedForms.SkewedRect(rect, BorderRadius);
                break;

            default:
                path = ExtendedForms.RoundedRect(rect, 0);
                break;
            }

            if (FigureType != FigureType.None)
            {
                g.SmoothingMode = SmoothingMode.HighQuality;
            }


            Brush      backBrush;
            Pen        borderPen;
            Pen        innerBorderPen;
            SolidBrush foreBrush;

            if (Enabled)
            {
                if (_isSelected && !_isPushed && !NormalStyle.Equals(HoverStyle))
                {
                    if (Palette == null)
                    {
                        backBrush      = HoverStyle.BackBrush;
                        borderPen      = HoverStyle.BorderPen;
                        innerBorderPen = HoverStyle.InnerBorderPen;
                        foreBrush      = HoverStyle.ForeBrush;
                    }
                    else
                    {
                        backBrush      = Palette.HoverStyle.BackBrush;
                        borderPen      = Palette.HoverStyle.BorderPen;
                        innerBorderPen = Palette.HoverStyle.InnerBorderPen;
                        foreBrush      = Palette.HoverStyle.ForeBrush;
                    }
                }
                else if (_isSelected && _isPushed)
                {
                    if (Palette == null)
                    {
                        if (!ButtonAnimation.Animated || !DrawPushAnimation)
                        {
                            backBrush = new SolidBrush(HoverStyle.BackColor.Darken(30));
                        }
                        else
                        {
                            backBrush = HoverStyle.BackBrush;
                        }
                        borderPen      = HoverStyle.BorderPen;
                        innerBorderPen = HoverStyle.InnerBorderPen;
                        foreBrush      = HoverStyle.ForeBrush;
                    }
                    else
                    {
                        backBrush      = Palette.HoverStyle.BackBrush;
                        borderPen      = Palette.HoverStyle.BorderPen;
                        innerBorderPen = Palette.HoverStyle.InnerBorderPen;
                        foreBrush      = Palette.HoverStyle.ForeBrush;
                    }
                }
                else
                {
                    if (Palette == null)
                    {
                        backBrush      = NormalStyle.BackBrush;
                        borderPen      = NormalStyle.BorderPen;
                        innerBorderPen = NormalStyle.InnerBorderPen;
                        foreBrush      = NormalStyle.ForeBrush;
                    }
                    else
                    {
                        backBrush      = Palette.NormalStyle.BackBrush;
                        borderPen      = Palette.NormalStyle.BorderPen;
                        innerBorderPen = Palette.NormalStyle.InnerBorderPen;
                        foreBrush      = Palette.NormalStyle.ForeBrush;
                    }
                }
            }
            else
            {
                if (Palette == null)
                {
                    backBrush      = DisabledStyle.BackBrush;
                    borderPen      = DisabledStyle.BorderPen;
                    innerBorderPen = DisabledStyle.InnerBorderPen;
                    foreBrush      = DisabledStyle.ForeBrush;
                }
                else
                {
                    backBrush      = Palette.DisabledStyle.BackBrush;
                    borderPen      = Palette.DisabledStyle.BorderPen;
                    innerBorderPen = Palette.DisabledStyle.InnerBorderPen;
                    foreBrush      = Palette.DisabledStyle.ForeBrush;
                }
            }

            g.FillPath(backBrush, path);


            if (DrawPushAnimation && ButtonAnimation.Animated)
            {
                GraphicsPath gp = new GraphicsPath();

                int length = ButtonAnimation.CurrentValue;

                gp.AddEllipse(new Rectangle(ButtonAnimation.MousePos.X - length, ButtonAnimation.MousePos.Y - length, length * 2, length * 2));

                Region region = new Region();
                region.Intersect(path);
                region.Intersect(gp);

                e.Graphics.FillRegion(new SolidBrush(HoverStyle.BackColor.Darken(20)), region);
            }


            if (_isSelected && DrawFlash)     //mouse blick
            {
                GraphicsPath gp = new GraphicsPath();

                int length = (ClientRectangle.Width + ClientRectangle.Height) / 4;

                gp.AddEllipse(new Rectangle(_mouseLocation.X - length, _mouseLocation.Y - length, length * 2, length * 2));

                PathGradientBrush pgb = new PathGradientBrush(gp);

                pgb.CenterPoint    = _mouseLocation;
                pgb.CenterColor    = Color.FromArgb(FlashAlpha, Color.White);
                pgb.SurroundColors = new Color[] { Color.FromArgb(0, Color.White) };

                e.Graphics.FillPath(pgb, gp);
            }


            if (DrawBorder)
            {
                g.DrawPath(borderPen, path);
            }

            if (DrawInnerBorder)
            {
                Rectangle innerRect = new Rectangle(rect.Location, rect.Size);
                innerRect.Inflate(-1, -1);

                int radius = 0;
                switch (FigureType)
                {
                case FigureType.Rounded:
                    radius = BorderRadius;
                    break;

                case FigureType.Skewed:
                    radius = BorderRadius;
                    break;
                }
                if (FigureType == WinformControls.FigureType.Skewed)
                {
                    g.DrawPath(innerBorderPen, ExtendedForms.SkewedRect(innerRect, radius));
                }
                else
                {
                    g.DrawPath(innerBorderPen, ExtendedForms.RoundedRect(innerRect, radius));
                }
            }

            if (_isSelected && _isPushed)
            {
                rect.Offset(0, 1);
            }

            g.SmoothingMode = SmoothingMode.HighSpeed;

            g.DrawString(Text, Font, foreBrush, rect, sf);
        }