コード例 #1
0
        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();
        }