Exemple #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (Width == 0)               // designer is throwing fits about this all of a sudden.
            {
                return;
            }

            Rectangle headerRect = new Rectangle(0, 0, Width, _headerHeight - 1);

            using (GraphicsPath path = DrawingHelper.CreateRoundedRectangle(1, 1, Width - 3, Height - 3, 3, DrawingHelper.RectangleCorners.TopLeft | DrawingHelper.RectangleCorners.TopRight))
                using (GraphicsPath borderPath = DrawingHelper.CreateRoundedRectangle(0, 0, Width - 1, Height - 1, 5, DrawingHelper.RectangleCorners.TopLeft | DrawingHelper.RectangleCorners.TopRight))
                    using (LinearGradientBrush gradBrush = new LinearGradientBrush(headerRect, _headerColorFrom, _headerColorTo, 90f))
                        using (Brush brush = new SolidBrush(ControlBackColor))
                            using (Pen borderPathPen = new Pen(Color.FromArgb(75, _shadowColor)))
                                using (Pen borderPen = new Pen(_borderColor))
                                    using (Pen separatorPen = new Pen(_seperatorColor)){
                                        e.Graphics.SetClip(headerRect);
                                        e.Graphics.FillPath(gradBrush, path);

                                        e.Graphics.ResetClip();

                                        e.Graphics.FillRectangle(brush, 1, _headerHeight, Width - 3, Height - 3 - (_headerHeight - 1));

                                        e.Graphics.DrawPath(borderPathPen, borderPath);
                                        e.Graphics.DrawPath(borderPen, path);
                                        e.Graphics.DrawLine(separatorPen, new Point(2, _headerHeight - 1), new Point(this.Width - 3, _headerHeight - 1));
                                    }

            PaintContent(e);
        }
        private void PaintButton(PaintEventArgs e)
        {
            GraphicsPath gp;
            GraphicsPath gpShadow;

            if (_isExpanded)
            {
                gp       = DrawingHelper.CreateRoundedRectangle(1, 1, this.Width - 3, _buttonHeight - 3, 3, DrawingHelper.RectangleCorners.TopLeft | DrawingHelper.RectangleCorners.TopRight);
                gpShadow = DrawingHelper.CreateRoundedRectangle(0, 0, this.Width - 1, _buttonHeight - 1, 5, DrawingHelper.RectangleCorners.TopLeft | DrawingHelper.RectangleCorners.TopRight);
            }
            else
            {
                gp       = DrawingHelper.CreateRoundedRectangle(1, 1, this.Width - 3, _buttonHeight - 3, 3);
                gpShadow = DrawingHelper.CreateRoundedRectangle(0, 0, this.Width - 1, _buttonHeight - 1, 5);
            }

            if (_isExpanded)
            {
                e.Graphics.FillRectangle(new SolidBrush(BackColor), new Rectangle(0, _buttonHeight / 2, this.Width - 3, this.Height - (_buttonHeight / 2) - 2));

                LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(0, 0, this.Width, _buttonHeight), _normalColorFrom, _normalColorTo, 90f);
                e.Graphics.FillPath(lgb, gp);
                lgb.Dispose();
            }
            else
            {
                if (_mouseDown)
                {
                    LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(0, 0, this.Width, _buttonHeight), _downColorFrom, _downColorTo, 90f);
                    e.Graphics.FillPath(lgb, gp);
                    lgb.Dispose();
                }
                else
                {
                    if (_mouseHovered)
                    {
                        LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(0, 0, this.Width, _buttonHeight), _hoverColorFrom, _hoverColorTo, 90f);
                        e.Graphics.FillPath(lgb, gp);
                        lgb.Dispose();
                    }
                    else
                    {
                        LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(0, 0, this.Width, _buttonHeight), _normalColorFrom, _normalColorTo, 90f);
                        e.Graphics.FillPath(lgb, gp);
                        lgb.Dispose();
                    }
                }
            }

            using (Pen pen = new Pen(_borderColor))
                using (Pen borderPen = new Pen(Color.FromArgb(75, _borderColor)))
                    using (Pen shadowPen = new Pen(Color.FromArgb(75, _shadowColor))) {
                        e.Graphics.DrawPath(shadowPen, gpShadow);
                        e.Graphics.DrawPath(pen, gp);

                        if (_isExpanded)
                        {
                            e.Graphics.DrawLine(pen, new Point(1, _buttonHeight - 1), new Point(1, Height - 2));
                            e.Graphics.DrawLine(shadowPen, new Point(0, _buttonHeight), new Point(0, Height - 1));

                            e.Graphics.DrawLine(pen, new Point(this.Width - 2, _buttonHeight - 1), new Point(this.Width - 2, Height - 2));
                            e.Graphics.DrawLine(shadowPen, new Point(this.Width - 1, _buttonHeight), new Point(this.Width - 1, Height - 1));

                            e.Graphics.DrawLine(pen, new Point(2, Height - 2), new Point(this.Width - 3, Height - 2));
                            e.Graphics.DrawLine(shadowPen, new Point(1, Height - 1), new Point(this.Width - 2, Height - 1));

                            e.Graphics.DrawLine(pen, new Point(2, _buttonHeight - 1), new Point(this.Width - 3, _buttonHeight - 1));
                            e.Graphics.DrawLine(new Pen(Color.FromArgb(200, 200, 200)), new Point(2, _buttonHeight - 2), new Point(this.Width - 3, _buttonHeight - 2));
                        }
                    }

            gp.Dispose();
            gpShadow.Dispose();
        }