Exemplo n.º 1
0
        private void DrawHeader(Bitmap headerBitmap, Color headerBorderColor, Color headerBackgroundColor, Rectangle headerRectangle)
        {
            Graphics innerGraphics = Graphics.FromImage(headerBitmap);

            if (HeaderFlatStyle)
            {
                innerGraphics.FillPath(new SolidBrush(headerBackgroundColor), ExtendedForms.RoundedRect(headerRectangle, BorderRadius));
            }
            else
            {
                LinearGradientBrush brush = new LinearGradientBrush(headerRectangle, headerBackgroundColor.Lighten(HeaderGradientLightenValue), headerBackgroundColor, LinearGradientMode.Vertical);
                innerGraphics.FillPath(brush, ExtendedForms.RoundedRect(headerRectangle, BorderRadius));
            }
            innerGraphics.DrawPath(new Pen(headerBorderColor, BorderThickness), ExtendedForms.RoundedRect(headerRectangle, BorderRadius));

            DrawString(innerGraphics, headerRectangle);

            if (ShowBottomBorder)
            {
                innerGraphics.DrawLine(
                    new Pen(headerBackgroundColor.Lighten(30)),
                    headerRectangle.X,
                    headerRectangle.Y + 1,
                    headerRectangle.Right,
                    headerRectangle.Y + 1);
                innerGraphics.DrawLine(
                    new Pen(headerBackgroundColor.Darken(30)),
                    headerRectangle.X,
                    headerRectangle.Bottom - 1,
                    headerRectangle.Right,
                    headerRectangle.Bottom - 1);
            }

            Graphics g = Graphics.FromHwnd(this.Handle);

            g.DrawImage(headerBitmap, headerRectangle.Location);
        }
Exemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            if (BorderRadius > 0)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
            }

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

            g.FillPath(new SolidBrush(BackColor), ExtendedForms.RoundedRect(rect, BorderRadius));


            if (Figure == ProgressBarFigure.Normal)
            {
                Rectangle progressRect = new Rectangle(_value, rect.Y + 2, IndicatorWidth, rect.Bottom - 3);

                Brush brush = new LinearGradientBrush(progressRect, BackColor, ProgressColor, 0F);   //new SolidBrush( ProgressColor );

                g.FillPath(brush, ExtendedForms.RoundedRect(progressRect, BorderRadius));
                _value++;
                if (_value > rect.Width)
                {
                    _value = -_indicatorWidth;
                }

                g.DrawPath(new Pen(BorderColor, BorderThickness), ExtendedForms.RoundedRect(rect, BorderRadius));
            }
            else
            {
                Rectangle arcRect = new Rectangle(ClientRectangle.X + IndicatorHeight / 2, ClientRectangle.Y + IndicatorHeight / 2, ClientRectangle.Width - BorderThickness - IndicatorHeight, ClientRectangle.Height - BorderThickness - IndicatorHeight);
                Color     color1;
                Color     color2;


                //g.FillPie( new SolidBrush( ProgressColor ), rect, 0, Value );
                _value++;
                if (_value >= 720)
                {
                    _value = 360;
                }
                //if ( _value > 360 ) {
                //    _value = 0;
                //    _delta *= -1;
                //}

                //if ( _delta > 0 ) {
                //    color1 = ProgressColor.SetAlpha( IndicatorBackAlpha );
                //    color2 = ProgressColor;
                //}
                //else {
                //    color1 = ProgressColor;
                //    color2 = ProgressColor.SetAlpha( IndicatorBackAlpha );
                //}

                //g.DrawArc( new Pen( color1, IndicatorHeight ), arcRect, 0, 360 );
                //g.DrawArc( new Pen( color2, IndicatorHeight ), arcRect, -90, _value );

                //Console.WriteLine( _value );



                g.DrawArc(new Pen(ProgressColor.SetAlpha(IndicatorBackAlpha), IndicatorHeight), arcRect, 0, 360);
                g.DrawArc(new Pen(ProgressColor, IndicatorHeight), arcRect, _value, IndicatorWidth);

                g.DrawArc(new Pen(Color.Black.SetAlpha(50), IndicatorHeight), arcRect, _value * -2, 1);


                //_alpha += _delta;
                //if ( _alpha > 255 ) {
                //    _alpha = 255;
                //    _delta *= -1;
                //}
                //if ( _alpha < 0 ) {
                //    _alpha = 0;
                //    _delta *= -1;
                //}
            }

            string text = (Style == ProgressBarStyle.Marquee) ? Text : Value.ToString();

            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment     = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;

            g.DrawString(
                text,
                this.Font,
                new SolidBrush(ForeColor),
                rect,
                stringFormat);
        }
        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);
        }
Exemplo n.º 4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics controlGraphics = e.Graphics;

            if (Parent != null)
            {
                controlGraphics.Clear(Parent.BackColor);
            }

            StringFormat stringFormat = new StringFormat()
            {
                LineAlignment = TextAlign.GetVerticalAlignment(),
                Alignment     = TextAlign.GetHorizontalAlignment()
            };

            controlGraphics.SmoothingMode = SmoothingMode.AntiAlias;

            SolidBrush foreBrush = NormalStyle.ForeBrush;

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

                SolidBrush backBrush;
                Pen        borderPen;

                if (Enabled)
                {
                    if (Palette == null)
                    {
                        backBrush = NormalStyle.BackBrush;
                        borderPen = NormalStyle.BorderPen;
                        foreBrush = NormalStyle.ForeBrush;
                    }
                    else
                    {
                        backBrush = Palette.NormalStyle.BackBrush;
                        borderPen = Palette.NormalStyle.BorderPen;
                        foreBrush = Palette.NormalStyle.ForeBrush;
                    }
                }
                else
                {
                    if (Palette == null)
                    {
                        backBrush = DisabledStyle.BackBrush;
                        borderPen = DisabledStyle.BorderPen;
                        foreBrush = DisabledStyle.ForeBrush;
                    }
                    else
                    {
                        backBrush = Palette.DisabledStyle.BackBrush;
                        borderPen = Palette.DisabledStyle.BorderPen;
                        foreBrush = Palette.DisabledStyle.ForeBrush;
                    }
                }

                controlGraphics.FillPath(backBrush, ExtendedForms.RoundedRect(rect, BorderRadius));
                controlGraphics.DrawPath(borderPen, ExtendedForms.RoundedRect(rect, BorderRadius));
            }

            Rectangle captionRect = new Rectangle(
                ClientRectangle.X + Padding.Left,
                ClientRectangle.Y + Padding.Top,
                ClientRectangle.Width - Padding.Horizontal,
                ClientRectangle.Height - Padding.Vertical);

            controlGraphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            if (DrawShadow && ShadowColor != null)
            {
                Rectangle shadowRect = captionRect;
                shadowRect.Offset(ShadowOffset);
                using (SolidBrush shadowBrush = new SolidBrush(ShadowColor)) {
                    controlGraphics.DrawString((AllCaps) ? Text.ToUpper() : Text, Font, shadowBrush, shadowRect, stringFormat);
                }
            }

            controlGraphics.DrawString((AllCaps) ? Text.ToUpper() : Text, Font, foreBrush, captionRect, stringFormat);
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

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

            g.SmoothingMode = SmoothingMode.AntiAlias;

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

            if (FillBackground)
            {
                if (!_isSelected)
                {
                    if (RadioButtonFlatStyle)
                    {
                        LinearGradientBrush gradient = new LinearGradientBrush(backgroundRect, BackColor.Lighten(5), BackColor.Darken(25), LinearGradientMode.Vertical);
                        g.FillPath(gradient, ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }
                    else
                    {
                        g.FillPath(new SolidBrush(BackColor), ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }

                    if (_useDarckenColorForBorder)
                    {
                        g.DrawPath(new Pen(BackColor.Darken(80), 1), ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }
                    else
                    {
                        g.DrawPath(new Pen(BorderColor, 1), ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }
                }
                else
                {
                    if (RadioButtonFlatStyle)
                    {
                        LinearGradientBrush gradient = new LinearGradientBrush(backgroundRect, BackColor.Lighten(30), BackColor.Lighten(15), LinearGradientMode.Vertical);
                        g.FillPath(gradient, ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }
                    else
                    {
                        g.FillPath(new SolidBrush(BackColor.Lighten(30)), ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }

                    if (_useDarckenColorForBorder)
                    {
                        g.DrawPath(new Pen(BorderColor.Lighten(20), 1), ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }
                    else
                    {
                        g.DrawPath(new Pen(BorderColor, 1), ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }
                }
            }

            int        dotDiameter = ThumbRadius;
            int        thumbY      = ClientRectangle.Height / 2 - dotDiameter / 2 - 1;
            RectangleF innerRect   = new RectangleF(Padding.Left + Spacing, thumbY, dotDiameter, dotDiameter);
            int        textX       = ( int )innerRect.Left + ( int )innerRect.Width + Spacing;


            SolidBrush thumbBackBrush = null;
            Pen        thumbBorderPen = new Pen(ThumbColor, 2);
            SolidBrush thumbDotBrush  = new SolidBrush(ThumbColor);

            if (_isSelected)
            {
                thumbBackBrush = _whiteBrush;
                thumbBorderPen = (RadioButtonFlatStyle) ?
                                 thumbBorderPen = new Pen(BackColor.Darken(120), 2) :
                                                  thumbBorderPen = new Pen(ThumbColor, 2);
            }
            else
            {
                thumbBackBrush = _whiteBrush;
                thumbBorderPen = (RadioButtonFlatStyle) ?
                                 thumbBorderPen = new Pen(BackColor.Darken(130), 2) :
                                                  thumbBorderPen = new Pen(ThumbColor, 2);
            }

            int count = (Checked || _isSelected) ? 2 : 1;

            for (int i = 0; i < count; i++)
            {
                if (RoundedThumb)
                {
                    g.FillEllipse(((Checked || _isSelected) && i > 0) ? thumbDotBrush : thumbBackBrush, innerRect);
                    g.DrawEllipse(thumbBorderPen, innerRect);
                }
                else
                {
                    g.FillRectangle(thumbBackBrush, innerRect);
                    g.DrawRectangle(thumbBorderPen, innerRect.X, innerRect.Y, innerRect.Width, innerRect.Height);
                }

                innerRect.Inflate(-4, -4);
            }


            StringFormat sf = new StringFormat();

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

            innerRect = new RectangleF(textX, 1, ClientRectangle.Width - 1 - dotDiameter - 2, ClientRectangle.Height - 3);

            SolidBrush textBrush = (ForeColor == Color.Black) ? _blackBrush : new SolidBrush(ForeColor);

            g.DrawString(Text, Font, textBrush, innerRect, sf);
        }
Exemplo n.º 7
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle toggleRect   = _toggleRect;
            int       _toggleWidth = toggleRect.Width;

            Graphics g = e.Graphics;


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

            g.SmoothingMode = SmoothingMode.HighQuality;

            int rectInflate = (toggleRect.Height - Font.Height);

            if (Font.Height < 15)
            {
                rectInflate = 2;
            }

            toggleRect.Offset(-1, 0);
            //toggleRect.Inflate( rectInflate * -1, rectInflate * -1 );

            toggleRect.Inflate(-1, -1);

            #region "Toggle drawing"
            Color toggleBackColor   = ToggleCheckedBackColor;
            Color toggleBorderColor = ToggleButtonStyle.BorderColor;// ToggleBorderColor;

            if (_selected)
            {
                toggleBackColor   = (Checked) ? ToggleCheckedHoverBackColor : ToggleUncheckedHoverBackColor;
                toggleBorderColor = ToggleBorderHoverColor;
            }
            else
            {
                toggleBackColor = (Checked) ? ToggleCheckedBackColor : ToggleUncheckedBackColor;
            }

            Brush backBrush = null;
            if (ToggleFlatStyle)
            {
                backBrush = new SolidBrush(toggleBackColor);
            }
            else
            {
                backBrush = new LinearGradientBrush(toggleRect, toggleBackColor, toggleBackColor.Lighten(20), 90);
            }

            g.FillPath(backBrush, ExtendedForms.RoundedRect(toggleRect, BorderRadius));
            g.DrawPath(new Pen(toggleBorderColor), ExtendedForms.RoundedRect(toggleRect, BorderRadius));


            Rectangle tempRect = toggleRect;
            tempRect.Inflate(-1, -1);
            g.DrawPath(new Pen(toggleBackColor.Lighten(20)), ExtendedForms.RoundedRect(tempRect, BorderRadius));

            //g.DrawLine( new Pen( Color.FromArgb( 80, 255, 255, 255 ) ), toggleRect.X + BorderRadius, toggleRect.Y + 1, toggleRect.Right - BorderRadius, toggleRect.Y + 1 );
            #endregion


            StringFormat sf = new StringFormat();
            sf.LineAlignment = StringAlignment.Center;
            sf.Alignment     = StringAlignment.Near;
            sf.FormatFlags   = StringFormatFlags.NoWrap;


            int offset = 3;
            if (BorderRadius > offset)
            {
                offset = BorderRadius;
            }

            Rectangle checkedRect   = new Rectangle(toggleRect.X + toggleRect.Width / 2, toggleRect.Y, toggleRect.Width / 2, toggleRect.Height);
            Rectangle unCheckedRect = new Rectangle(toggleRect.X, toggleRect.Y, toggleRect.Width / 2, toggleRect.Height);
            if (Checked)
            {
                Brush brush = null;

                if (ToggleFlatStyle)
                {
                    brush = new SolidBrush(ToggleButtonStyle.BackColor);
                }
                else
                {
                    brush = new LinearGradientBrush(checkedRect, ToggleButtonStyle.BackColor.Lighten(30), ToggleButtonStyle.BackColor, 90);
                }

                //g.FillPath( brush, ExtendedForms.RoundedLeftRect( checkedRect, BorderRadius ) );
                //g.DrawPath( new Pen( ToggleButtonStyle.BorderColor ), ExtendedForms.RoundedLeftRect( checkedRect, BorderRadius ) );
                checkedRect.Inflate(-2, -2);
                g.FillPath(brush, ExtendedForms.RoundedRect(checkedRect, BorderRadius));
                g.DrawPath(new Pen(ToggleButtonStyle.BorderColor), ExtendedForms.RoundedRect(checkedRect, BorderRadius));

                tempRect = checkedRect;
                tempRect.Inflate(-1, -1);
                g.DrawPath(new Pen(ToggleButtonStyle.BackColor.Lighten(20)), ExtendedForms.RoundedRect(tempRect, BorderRadius));
            }
            else
            {
                Brush brush = null;

                if (ToggleFlatStyle)
                {
                    brush = new SolidBrush(ToggleButtonStyle.BackColor);
                }
                else
                {
                    brush = new LinearGradientBrush(checkedRect, ToggleButtonStyle.BackColor.Lighten(30), ToggleButtonStyle.BackColor, 90);
                }

                //g.FillPath( brush, ExtendedForms.RoundedRightRect( unCheckedRect, BorderRadius ) );
                //g.DrawPath( new Pen( ToggleButtonStyle.BorderColor ), ExtendedForms.RoundedRightRect( unCheckedRect, BorderRadius ) );

                unCheckedRect.Inflate(-2, -2);
                g.FillPath(brush, ExtendedForms.RoundedRect(unCheckedRect, BorderRadius));
                g.DrawPath(new Pen(ToggleButtonStyle.BorderColor), ExtendedForms.RoundedRect(unCheckedRect, BorderRadius));


                tempRect = unCheckedRect;
                tempRect.Inflate(-1, -1);
                g.DrawPath(new Pen(ToggleButtonStyle.BackColor.Lighten(20)), ExtendedForms.RoundedRect(tempRect, BorderRadius));
            }



            //unCheckedRect.Inflate( -( 4 ), -( 4 ) );

            g.SmoothingMode = SmoothingMode.HighSpeed;

            if (ToggleShowIcon)
            {
                if (Checked)
                {
                    int centerY = (unCheckedRect.Bottom - unCheckedRect.Top) / 2 + 2;
                    int centerX = unCheckedRect.Left + (unCheckedRect.Right - unCheckedRect.Left) / 2 + 1;

                    g.DrawLine(new Pen(ForeChechedColor, 2), centerX - LineHalfLength, centerY, centerX + LineHalfLength, centerY);
                    g.DrawLine(new Pen(ForeChechedColor, 2), centerX, centerY - LineHalfLength, centerX, centerY + LineHalfLength);
                }
                else
                {
                    int centerY = (checkedRect.Bottom - checkedRect.Top) / 2 + 2;
                    int centerX = (checkedRect.Right + (checkedRect.Right - checkedRect.Left)) / 2 + 1;

                    g.DrawLine(new Pen(ForeUnchechedColor, 2), centerX - LineHalfLength, centerY, centerX + LineHalfLength, centerY);
                }
            }

            Rectangle innerRect = new Rectangle(
                ClientRectangle.X + _toggleWidth + 2,
                ClientRectangle.Y,
                ClientRectangle.Width - ClientRectangle.X - _toggleWidth,
                ClientRectangle.Height);

            Color foreColor = (_selected) ? ForeHoverColor : ForeColor;

            g.DrawString(Text, Font, new SolidBrush(foreColor), innerRect, sf);
        }
Exemplo n.º 8
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

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

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;


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

            int toggleWidth = toggleRect.Width;

            if (Appearance == Appearance.Normal)
            {
                int rectInflate = 3; //( toggleRect.Height - Font.Height );
                if (Font.Height < 15)
                {
                    rectInflate = 3;
                }

                toggleRect.Offset(-rectInflate, 0);
                toggleRect.Inflate(-rectInflate * 1, -rectInflate * 1);

                if (_selected)
                {
                    g.FillPath(new SolidBrush(ToggleHoverBackColor), ExtendedForms.RoundedRect(toggleRect, BorderRadius));
                    g.DrawPath(new Pen(ToggleBorderHoverColor), ExtendedForms.RoundedRect(toggleRect, BorderRadius));
                }
                else
                {
                    g.FillPath(new SolidBrush(ToggleBackColor), ExtendedForms.RoundedRect(toggleRect, BorderRadius));
                    g.DrawPath(new Pen(ToggleBorderColor), ExtendedForms.RoundedRect(toggleRect, BorderRadius));
                }

                int offset = 3;
                if (BorderRadius > offset)
                {
                    offset = BorderRadius;
                }

                if (Checked)
                {
                    g.DrawLine(new Pen(ToggleColor, 2), toggleRect.X + offset, toggleRect.Y + offset, toggleRect.Right - offset, toggleRect.Bottom - offset);
                    g.DrawLine(new Pen(ToggleColor, 2), toggleRect.Right - offset, toggleRect.Y + offset, toggleRect.X + offset, toggleRect.Bottom - offset);
                }


                StringFormat sf = new StringFormat();
                sf.LineAlignment = StringAlignment.Center;
                sf.Alignment     = StringAlignment.Near;
                sf.FormatFlags   = StringFormatFlags.NoWrap;

                Rectangle innerRect = new Rectangle(
                    ClientRectangle.X + toggleWidth,
                    ClientRectangle.Y,
                    ClientRectangle.Width - ClientRectangle.X - toggleWidth,
                    ClientRectangle.Height);
                g.DrawString(Checked ? TextChecked : Text, Font, new SolidBrush(Checked ? CheckedForeColor : ForeColor), innerRect, sf);
            }
            else
            {
                Rectangle checkBoxRect = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1);

                if (_selected)
                {
                    g.FillPath(new SolidBrush(ToggleHoverBackColor), ExtendedForms.RoundedRect(checkBoxRect, BorderRadius));
                    g.DrawPath(new Pen(ToggleBorderHoverColor), ExtendedForms.RoundedRect(checkBoxRect, BorderRadius));
                }
                else
                {
                    if (Checked)
                    {
                        g.FillPath(new SolidBrush(ToggleCheckedBackColor), ExtendedForms.RoundedRect(checkBoxRect, BorderRadius));
                        g.DrawPath(new Pen(ToggleCheckedBorderColor), ExtendedForms.RoundedRect(checkBoxRect, BorderRadius));
                    }
                    else
                    {
                        g.FillPath(new SolidBrush(ToggleBackColor), ExtendedForms.RoundedRect(checkBoxRect, BorderRadius));
                        g.DrawPath(new Pen(ToggleBorderColor), ExtendedForms.RoundedRect(checkBoxRect, BorderRadius));
                    }
                }

                StringFormat sf = new StringFormat();
                sf.LineAlignment = StringAlignment.Center;
                sf.Alignment     = StringAlignment.Center;
                sf.FormatFlags   = StringFormatFlags.NoWrap;

                g.DrawString(Checked ? TextChecked : Text, Font, new SolidBrush(Checked ? CheckedForeColor : ForeColor), checkBoxRect, sf);
            }
        }
Exemplo n.º 9
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);
        }