protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

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

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

            if (DrawCaptionBackground)
            {
                g.FillPath(new SolidBrush(NormalStyle.BackColor), ExtendedForms.RoundedLeftRect(clientRect, BorderRadius));
                g.DrawPath(new Pen(NormalStyle.BorderColor), ExtendedForms.RoundedLeftRect(clientRect, BorderRadius));
            }

            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Center;
            switch (TextAlign)
            {
            case ContentAlignment.BottomLeft:
                sf.Alignment = StringAlignment.Near;
                break;

            case ContentAlignment.MiddleLeft:
                sf.Alignment = StringAlignment.Near;
                break;

            case ContentAlignment.TopLeft:
                sf.Alignment = StringAlignment.Near;
                break;

            case ContentAlignment.BottomCenter:
                sf.Alignment = StringAlignment.Center;
                break;

            case ContentAlignment.MiddleCenter:
                sf.Alignment = StringAlignment.Center;
                break;

            case ContentAlignment.TopCenter:
                sf.Alignment = StringAlignment.Center;
                break;

            case ContentAlignment.BottomRight:
                sf.Alignment = StringAlignment.Far;
                break;

            case ContentAlignment.MiddleRight:
                sf.Alignment = StringAlignment.Far;
                break;

            case ContentAlignment.TopRight:
                sf.Alignment = StringAlignment.Far;
                break;
            }

            g.SmoothingMode = SmoothingMode.AntiAlias;

            int captionHeight = GetCaptionSize().Height;// ( int ) g.MeasureString( Caption, Font ).Width;// +2 * _spacing;

            Rectangle captionRect = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, captionHeight);

            if (DrawCaptionBackground)
            {
                g.FillPath(new SolidBrush(CaptionNormalStyle.BackColor), ExtendedForms.RoundedLeftRect(captionRect, BorderRadius));
                g.DrawLine(new Pen(NormalStyle.BorderColor), captionRect.X, captionRect.Bottom, captionRect.Right, captionRect.Bottom);
            }
            else
            {
                //g.FillPath( new SolidBrush( Parent.BackColor ), ExtendedForms.RoundedLeftRect( captionRect, BorderRadius ) );
                //g.DrawLine( new Pen( NormalStyle.BorderColor ), captionRect.X, captionRect.Bottom, captionRect.Right, captionRect.Bottom );
            }
            //g.FillPath( new SolidBrush( BackColor ), ExtendedForms.RoundedRightRect( textRect, BorderRadius ) );

            //g.DrawPath( new Pen( BorderColor ), ExtendedForms.RoundedLeftRect( captionRect, BorderRadius ) );
            //g.DrawPath( new Pen( BorderColor ), ExtendedForms.RoundedRightRect( textRect, BorderRadius ) );

            //Rectangle innerCaptionRect = captionRect;
            //innerCaptionRect.Inflate( -1, -1 );
            //g.DrawPath( new Pen( CaptionNormalStyle.BackColor.Lighten( CaptionNormalStyle.InnerBorderPenLightenValue ) ), ExtendedForms.RoundedLeftRect( innerCaptionRect, BorderRadius ) );

            g.SmoothingMode = SmoothingMode.HighSpeed;

            //captionRect.Offset( _spacing, 0 );
            //textRect.Offset( _spacing, 0 );

            //Rectangle captionRect = new Rectangle( ClientRectangle.Location, new Size( captionWidth, ClientRectangle.Size.Height ) );

            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            captionRect         = new Rectangle(
                ClientRectangle.X + Padding.Left,
                ClientRectangle.Y + Padding.Top,
                ClientRectangle.Width - 1 - Padding.Left - Padding.Right,
                captionHeight - Padding.Top - Padding.Bottom);

            g.DrawString((AllCaps) ? Caption.ToUpper() : Caption, Font, new SolidBrush(CaptionNormalStyle.ForeColor), captionRect, sf);

            //Rectangle textRect = new Rectangle( new Point( captionWidth, ClientRectangle.Location.Y ), ClientRectangle.Size );

            //g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            //g.DrawString( ( AllCaps ) ? Text.ToUpper() : Text, Font, new SolidBrush( ForeColor ), textRect, sf );
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Center;

            switch (CaptionTextAlignment)
            {
            case HorizontalAlignment.Center:
                sf.Alignment = StringAlignment.Center;
                break;

            case HorizontalAlignment.Left:
                sf.Alignment = StringAlignment.Near;
                break;

            case HorizontalAlignment.Right:
                sf.Alignment = StringAlignment.Far;
                break;
            }

            StateStyle style = NormalStyle;

            if (!Error)
            {
                if (_isSelected)
                {
                    style = HoverStyle;
                }
            }
            else
            {
                style = ErrorStyle;
            }

            if (!Enabled)
            {
                style = DisabledStyle;
            }

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

            g.SmoothingMode = SmoothingMode.HighQuality;

            Rectangle textRect = new Rectangle(
                ClientRectangle.X,
                ClientRectangle.Y,
                ClientRectangle.Width - BorderThickness,
                ClientRectangle.Height - BorderThickness);
            Rectangle captionRect = new Rectangle();

            GraphicsPath textPath    = ExtendedForms.RoundedRect(textRect, BorderRadius);
            GraphicsPath captionPath = null;

            if (_captionSize.Width > 0)
            {
                switch (CaptionPosition)
                {
                case ContentPosition.Left:
                    captionRect = new Rectangle(
                        ClientRectangle.X,
                        ClientRectangle.Y,
                        _captionSize.Width + 2 * BorderPadding,
                        Height - BorderThickness);
                    textRect = new Rectangle(
                        captionRect.Width,
                        ClientRectangle.Y,
                        ClientRectangle.Width - BorderThickness - captionRect.Width,
                        ClientRectangle.Height - BorderThickness);

                    if (CaptionShowBorder)
                    {
                        textPath    = ExtendedForms.RoundedRightRect(textRect, BorderRadius);
                        captionPath = ExtendedForms.RoundedLeftRect(captionRect, BorderRadius);
                    }
                    else
                    {
                        textPath = ExtendedForms.RoundedRect(textRect, BorderRadius);
                    }
                    break;

                case ContentPosition.Right:
                    captionRect = new Rectangle(
                        ClientRectangle.Right - (_captionSize.Width + 2 * BorderPadding) - BorderThickness,
                        ClientRectangle.Y,
                        _captionSize.Width + 2 * BorderPadding,
                        Height - BorderThickness);
                    textRect = new Rectangle(
                        ClientRectangle.X,
                        ClientRectangle.Y,
                        ClientRectangle.Width - BorderThickness - captionRect.Width,
                        ClientRectangle.Height - BorderThickness);

                    if (CaptionShowBorder)
                    {
                        textPath    = ExtendedForms.RoundedLeftRect(textRect, BorderRadius);
                        captionPath = ExtendedForms.RoundedRightRect(captionRect, BorderRadius);
                    }
                    else
                    {
                        textPath = ExtendedForms.RoundedRect(textRect, BorderRadius);
                    }

                    break;

                case ContentPosition.Top:
                    captionRect = new Rectangle(
                        ClientRectangle.X,
                        ClientRectangle.Y,
                        ClientRectangle.Width - BorderThickness,
                        ClientRectangle.Y + _captionSize.Height + BorderPadding);
                    textRect = new Rectangle(
                        ClientRectangle.X,
                        ClientRectangle.Y + captionRect.Height,
                        ClientRectangle.Width - BorderThickness,
                        ClientRectangle.Height - captionRect.Height - BorderThickness);

                    if (CaptionShowBorder)
                    {
                        textPath    = ExtendedForms.RoundedBottomRect(textRect, BorderRadius);
                        captionPath = ExtendedForms.RoundedTopRect(captionRect, BorderRadius);
                    }
                    else
                    {
                        textPath = ExtendedForms.RoundedRect(textRect, BorderRadius);
                    }

                    break;

                case ContentPosition.Bottom:
                    captionRect = new Rectangle(
                        ClientRectangle.X,
                        ClientRectangle.Height - (_captionSize.Height + BorderPadding) - 1,
                        ClientRectangle.Width - BorderThickness,
                        _captionSize.Height + BorderPadding);
                    textRect = new Rectangle(
                        ClientRectangle.X,
                        ClientRectangle.Y,
                        ClientRectangle.Width - BorderThickness,
                        ClientRectangle.Height - captionRect.Height - BorderThickness);

                    if (CaptionShowBorder)
                    {
                        textPath    = ExtendedForms.RoundedTopRect(textRect, BorderRadius);
                        captionPath = ExtendedForms.RoundedBottomRect(captionRect, BorderRadius);
                    }
                    else
                    {
                        textPath = ExtendedForms.RoundedRect(textRect, BorderRadius);
                    }
                    break;
                }
            }

            g.FillPath(new SolidBrush(style.BackColor), textPath);

            if (_captionSize.Width > 0 && captionPath != null && CaptionShowBorder)
            {
                if (CaptionFlatStyle)
                {
                    g.FillPath(new SolidBrush(CaptionNormalStyle.BackColor), captionPath);
                }
                else
                {
                    g.FillPath(new LinearGradientBrush(captionRect, CaptionNormalStyle.BackColor.Lighten(20), CaptionNormalStyle.BackColor, 90), captionPath);
                    switch (CaptionPosition)
                    {
                    case ContentPosition.Left:
                        g.DrawLine(new Pen(CaptionNormalStyle.BackColor.Lighten(40)), captionRect.X + BorderRadius, captionRect.Top + 1, captionRect.Right, captionRect.Top + 1);
                        break;

                    case ContentPosition.Right:
                        g.DrawLine(new Pen(CaptionNormalStyle.BackColor.Lighten(40)), captionRect.X, captionRect.Top + 1, captionRect.Right - BorderRadius, captionRect.Top + 1);
                        break;
                    }
                }
            }

            if (_captionSize.Width > 0 && captionPath != null)
            {
                g.DrawPath(new Pen(style.BorderColor, BorderThickness), captionPath);
            }

            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            Rectangle captionTempRect = new Rectangle(captionRect.Location, captionRect.Size);

            if (CaptionPosition == ContentPosition.Left || CaptionPosition == ContentPosition.Right)
            {
                captionTempRect.Inflate(0, -BorderPadding / 2 - 2 * BorderThickness);
            }
            else
            {
                captionTempRect.Inflate(-BorderPadding / 2 - 2 * BorderThickness, 0);
                if (CaptionImage != null)
                {
                    captionTempRect.Offset(CaptionImageSize.Width + BorderPadding - 1, 0);
                }
            }

            g.DrawString(Caption, this.Font, new SolidBrush(CaptionNormalStyle.ForeColor), captionTempRect, sf);
            if (CaptionImage != null)
            {
                int imageY = captionTempRect.Y + (captionTempRect.Bottom - captionTempRect.Y) / 2 - CaptionImageSize.Height / 2;
                g.DrawImage(CaptionImage, captionTempRect.X - (_captionSize.Height + BorderPadding), imageY, CaptionImageSize.Width, CaptionImageSize.Height);
            }

            if (_captionSize.Width > 0 && CaptionShowBorder)
            {
                switch (CaptionPosition)
                {
                case ContentPosition.Left:
                    g.DrawLine(new Pen(style.BorderColor, BorderThickness), captionRect.Right, 0, captionRect.Right, Height);
                    break;

                case ContentPosition.Right:
                    g.DrawLine(new Pen(style.BorderColor, BorderThickness), captionRect.Left, 0, captionRect.Left, Height);
                    break;
                }
            }

            g.DrawPath(new Pen(style.BorderColor, BorderThickness), textPath);
        }