Example #1
0
        // Draws the button on the specified Grapics
        // in the specified state.
        //
        // Parameters:
        //  gr - The Graphics object on which to draw the button.
        //  pressed - If true, the button is drawn in the depressed state.
        private void DrawButton(Graphics gr, bool pressed)
        {
            // Get a Graphics object from the background image.
            Graphics gr2 = Graphics.FromImage(DoubleBufferImage);

            // Fill solid up until where the gradient fill starts.
            if (_StartOffset > 0)
            {
                if (_FillDirection == GradientFill.FillDirection.LeftToRight)
                {
                    gr2.FillRectangle(
                        new SolidBrush((pressed ^ _ReverseGradient) ? EndColor : StartColor),
                        0, 0, _StartOffset, Height);
                }
                else
                {
                    gr2.FillRectangle(new SolidBrush((pressed ^ _ReverseGradient) ? EndColor : StartColor),
                                      0, 0, Width, _StartOffset);
                }
            }

            // Draw the gradient fill.
            Rectangle rc = this.ClientRectangle;

            if (_FillDirection == GradientFill.FillDirection.LeftToRight)
            {
                rc.X     = _StartOffset;
                rc.Width = rc.Width - _StartOffset - _EndOffset;
            }
            else
            {
                rc.Y      = _StartOffset;
                rc.Height = rc.Height - _StartOffset - _EndOffset;
            }
            GradientFill.Fill(
                gr2,
                rc,
                (pressed ^ _ReverseGradient) ? _EndColor : _StartColor,
                (pressed ^ _ReverseGradient) ? _StartColor : _EndColor,
                _FillDirection);

            // Fill solid from the end of the gradient fill
            // to the edge of the button.
            if (_EndOffset > 0)
            {
                if (_FillDirection == GradientFill.FillDirection.LeftToRight)
                {
                    gr2.FillRectangle(new SolidBrush((pressed ^ _ReverseGradient) ? StartColor : EndColor),
                                      rc.X + rc.Width, 0, _EndOffset, Height);
                }
                else
                {
                    gr2.FillRectangle(new SolidBrush((pressed ^ _ReverseGradient) ? StartColor : EndColor),
                                      0, rc.Y + rc.Height, Width, _EndOffset);
                }
            }

            // Draw the text.
            StringFormat sf = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            gr2.DrawString(this.Text, this.Font,
                           new SolidBrush(this.ForeColor),
                           this.ClientRectangle, sf);

            // Draw the border.
            // Need to shrink the width and height by 1 otherwise
            // there will be no border on the right or bottom.
            rc = this.ClientRectangle;
            rc.Width--;
            rc.Height--;
            Pen pen = new Pen(SystemColors.WindowFrame);

            gr2.DrawRectangle(pen, rc);

            // Draw from the background image onto the screen.
            gr.DrawImage(DoubleBufferImage, 0, 0);
            gr2.Dispose();
        }
Example #2
0
        // Draws the button on the specified Grapics
        // in the specified state.
        //
        // Parameters:
        //  gr - The Graphics object on which to draw the button.
        //  pressed - If true, the button is drawn in the depressed state.
        private void DrawPanel(Graphics gr)
        {
            // Get a Graphics object from the background image.
            Graphics gr2 = Graphics.FromImage(DoubleBufferImage);

            // Fill solid up until where the gradient fill starts.
            if (startOffset > 0)
            {
                if (fillDirection == GradientFill.FillDirection.LeftToRight)
                {
                    gr2.FillRectangle(
                        new SolidBrush((reverseGradient) ? EndColor : StartColor),
                        0, 0, startOffset, Height);
                }
                else
                {
                    gr2.FillRectangle(new SolidBrush((reverseGradient) ? EndColor : StartColor),
                                      0, 0, Width, startOffset);
                }
            }

            // Draw the gradient fill.
            Rectangle rc = this.ClientRectangle;

            if (fillDirection == GradientFill.FillDirection.LeftToRight)
            {
                rc.X     = startOffset;
                rc.Width = rc.Width - startOffset - endOffset;
            }
            else
            {
                rc.Y      = startOffset;
                rc.Height = rc.Height - startOffset - endOffset;
            }
            GradientFill.Fill(
                gr2,
                rc,
                (reverseGradient) ? endColor : startColor,
                (reverseGradient) ? startColor : endColor,
                fillDirection);

            // Fill solid from the end of the gradient fill
            // to the edge of the button.
            if (endOffset > 0)
            {
                if (fillDirection == GradientFill.FillDirection.LeftToRight)
                {
                    gr2.FillRectangle(new SolidBrush((reverseGradient) ? StartColor : EndColor),
                                      rc.X + rc.Width, 0, endOffset, Height);
                }
                else
                {
                    gr2.FillRectangle(new SolidBrush((reverseGradient) ? StartColor : EndColor),
                                      0, rc.Y + rc.Height, Width, endOffset);
                }
            }

            if (border > 0)
            {
                // Draw the border.
                // Need to shrink the width and height by 1 otherwise
                // there will be no border on the right or bottom.
                rc        = this.ClientRectangle;
                rc.Width  = rc.Width - border;
                rc.Height = rc.Height - border;
                Pen pen = new Pen(SystemColors.WindowFrame);

                gr2.DrawRectangle(pen, rc);
            }
            // Draw from the background image onto the screen.
            gr.DrawImage(DoubleBufferImage, 0, 0);
            gr2.Dispose();
        }