Пример #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);
            }
        }