Esempio n. 1
0
        /// <summary>Draws the button.</summary>
        /// <param name="graphics">The graphics to draw on.</param>
        /// <param name="rectangle">The rectangle to draw on.</param>
        private void DrawButton(Graphics graphics, Rectangle rectangle)
        {
            if (!_buttonVisible)
            {
                return;
            }

            Point _buttonImageLocation;
            Size  _buttonImageSize;

            switch (_buttonStyle)
            {
            case ButtonStyles.Arrow:
            {
                _buttonImageSize     = new Size(10, 6);
                _buttonImageLocation = new Point((rectangle.X + (rectangle.Width / 2)) - (_buttonImageSize.Width / 2), (rectangle.Y + (rectangle.Height / 2)) - (_buttonImageSize.Height / 2));
                VisualElementRenderer.RenderTriangle(graphics, new Rectangle(_buttonImageLocation, _buttonImageSize), _buttonColor, Alignment.Vertical.Down);

                break;
            }

            case ButtonStyles.Bars:
            {
                _buttonImageSize     = new Size(18, 10);
                _buttonImageLocation = new Point((rectangle.X + (rectangle.Width / 2)) - (_buttonImageSize.Width / 2), (rectangle.Y + (rectangle.Height / 2)) - _buttonImageSize.Height);
                VisualElementRenderer.RenderBars(graphics, _buttonImageLocation, _buttonImageSize, _buttonColor, 3, 5);

                break;
            }

            case ButtonStyles.Image:
            {
                if (_buttonImage != null)
                {
                    _buttonImageLocation = new Point((rectangle.X + (rectangle.Width / 2)) - (_buttonImage.Width / 2), (rectangle.Y + (rectangle.Height / 2)) - (_buttonImage.Height / 2));
                    graphics.DrawImage(_buttonImage, _buttonImageLocation);
                }

                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException();
            }
            }
        }
Esempio n. 2
0
 /// <summary>Draws the expander button.</summary>
 /// <param name="graphics">The graphics to draw on.</param>
 /// <param name="rectangle">The button rectangle.</param>
 /// <param name="color">The button color.</param>
 /// <param name="state">The expanded toggle.</param>
 public static void Draw(Graphics graphics, Rectangle rectangle, Color color, bool state)
 {
     VisualElementRenderer.RenderTriangle(graphics, rectangle, color, state ? Alignment.Vertical.Up : Alignment.Vertical.Down);
 }
        protected override void OnPaint(PaintEventArgs e)
        {
            try
            {
                if (GetStyle(ControlStyles.AllPaintingInWmPaint))
                {
                    OnPaintBackground(e);
                }

                MinimumSize = new Size(0, GetPreferredSize(Size.Empty).Height);

                Rectangle    _clientRectangle    = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
                GraphicsPath controlGraphicsPath = VisualBorderRenderer.CreateBorderTypePath(_clientRectangle, _border);
                Color        backColorState      = ColorState.BackColorState(_backColor, Enabled, MouseState);

                e.Graphics.SetClip(controlGraphicsPath);
                VisualBackgroundRenderer.DrawBackground(e.Graphics, backColorState, BackgroundImage, MouseState, _clientRectangle, _border);
                VisualBorderRenderer.DrawBorderStyle(e.Graphics, _border, controlGraphicsPath, _mouseState);
                Rectangle arrowRectangle = new Rectangle(Width - _arrowSize.Width - 5, (Height / 2) - (_arrowSize.Height / 2), _arrowSize.Width, _arrowSize.Height);

                if (_image != null)
                {
                    e.Graphics.DrawImage(_image, new Rectangle(arrowRectangle.Left - _image.Width - 2, (Height / 2) - (_image.Height / 2), _imageSize.Width, _imageSize.Height));
                }

                VisualElementRenderer.RenderTriangle(e.Graphics, _arrowColor, _arrowDisabledColor, Enabled, _dropDownImage, arrowRectangle, Alignment.Vertical.Down);

                var       _check            = 0;
                Rectangle checkBoxRectangle = new Rectangle(3, (Height / 2) - 6, 12, 12);

                if (ShowCheckBox)
                {
                    _check = 15;

                    if (Checked)
                    {
                        CheckBoxRenderer.DrawCheckBox(e.Graphics, checkBoxRectangle.Location, CheckBoxState.CheckedNormal);
                    }
                    else
                    {
                        CheckBoxRenderer.DrawCheckBox(e.Graphics, checkBoxRectangle.Location, CheckBoxState.UncheckedNormal);
                    }
                }

                Size textSize = TextManager.MeasureText(Text, Font);

                Rectangle textBoxRectangle = new Rectangle(2 + _check, (Height / 2) - (textSize.Height / 2), textSize.Width, textSize.Height);
                TextRenderer.DrawText(e.Graphics, Text, Font, textBoxRectangle, ForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);

                if (_showFocus && _focused)
                {
                    ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle);
                }

                e.Graphics.ResetClip();
            }
            catch
            {
                Invalidate();
            }
        }