CustomChrome.VisualStudioButtonPaintEventArgs.PaintBackground C# (CSharp) Method

PaintBackground() public method

public PaintBackground ( ) : void
return void
        public void PaintBackground()
        {
            ChromeButtonState state = 0;
            if (Button.IsOver)
                state = ChromeButtonState.Over;
            else if (Button.IsDown)
                state = ChromeButtonState.Down;

            Graphics.FillRectangle(Button.Chrome.GetButtonBackgroundBrush(state), Bounds);
        }

Usage Example

            void chromeButton_Paint(object sender, VisualStudioButtonPaintEventArgs e)
            {
                var chromeButton = (VisualStudioButton)sender;
                var button = (TitleBarButton)chromeButton.Tag;

                if (chromeButton.Enabled && !chromeButton.IsOver && !chromeButton.IsDown && button.BackColor.HasValue)
                {
                    using (var brush = new SolidBrush(button.BackColor.Value))
                    {
                        e.Graphics.FillRectangle(brush, e.Bounds);
                    }
                }
                else
                {
                    e.PaintBackground();
                }

                if (button.Image != null)
                {
                    Bitmap image;

                    if (!chromeButton.Enabled)
                        image = button.DisabledImage;
                    else if (chromeButton.IsOver)
                        image = button.OverImage;
                    else if (chromeButton.IsDown)
                        image = button.DownImage;
                    else
                        image = button.EnabledImage;

                    e.Graphics.DrawImageUnscaled(
                        image,
                        e.Bounds.Left + ButtonImageOffset.X,
                        e.Bounds.Top + ButtonImageOffset.Y
                    );
                }
            }