protected override void OnPaint()

in sources/Google.Solutions.Mvvm/Controls/VerticalTabControl.cs [103:205]


        protected override void OnPaint(PaintEventArgs e)
        {
            var g = e.Graphics;

            using (var sheetBackgroundBrush = new SolidBrush(this.SheetBackColor))
            using (var activeBackgroundBrush = new SolidBrush(this.ActiveTabBackColor))
            using (var activeBackgroundPen = new Pen(this.ActiveTabBackColor))
            using (var activeTextBrush = new SolidBrush(this.ActiveTabForeColor))
            using (var inactiveBackgroundBrush = new SolidBrush(this.InactiveTabBackColor))
            using (var inactiveBackgroundPen = new Pen(this.InactiveTabBackColor))
            using (var inactiveTextBrush = new SolidBrush(this.InactiveTabForeColor))
            using (var hoverBackgroundBrush = new SolidBrush(this.HoverTabBackColor))
            using (var hoverBackgroundPen = new Pen(this.HoverTabBackColor))
            using (var hoverTextBrush = new SolidBrush(this.HoverTabForeColor))
            using (var centerNearFormat = new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Alignment = StringAlignment.Near
            })
            {
                //
                // Draw rectangle containing the tabs,
                //
                g.FillRectangle(
                    inactiveBackgroundBrush,
                    new Rectangle(0, 0, this.TabWidth + 4, this.Height));

                g.FillRectangle(
                    sheetBackgroundBrush,
                    new Rectangle(this.TabWidth + 4, 0, this.Width - this.TabWidth - 4, this.Height));

                for (var i = 0; i <= this.TabCount - 1; i++)
                {
                    //
                    // Use the tab rect, but leave some space at the left for the arrow
                    //
                    var boxRect = new Rectangle(
                        new Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y),
                        new Size(GetTabRect(i).Width - 6, GetTabRect(i).Height));
                    var textRect = new Rectangle(
                        boxRect.X + this.textMargin,
                        boxRect.Y,
                        boxRect.Width - this.textMargin,
                        boxRect.Height);

                    if (i == this.SelectedIndex)
                    {
                        //
                        // Draw active tab.
                        //

                        g.DrawRectangle(activeBackgroundPen, boxRect);
                        g.FillRectangle(activeBackgroundBrush, boxRect);

                        //
                        // Draw the little arrow.
                        //
                        g.SmoothingMode = SmoothingMode.HighQuality;
                        Point[] arrowPoints =
                        {
                            new Point(this.TabWidth + 3, GetTabRect(i).Location.Y + boxRect.Height / 2), // 20),
                            new Point(this.TabWidth - 4, GetTabRect(i).Location.Y + boxRect.Height / 2 - 7), // 14),
                            new Point(this.TabWidth - 4, GetTabRect(i).Location.Y + boxRect.Height / 2 + 7), // 27)
                        };

                        g.FillPolygon(activeBackgroundBrush, arrowPoints);

                        g.DrawString(
                            this.TabPages[i].Text,
                            this.Font,
                            activeTextBrush,
                            textRect,
                            centerNearFormat);
                    }
                    else if (GetTabRect(i).Contains(PointToClient(Cursor.Position)))
                    {
                        //
                        // Draw mouseover tab.
                        //
                        g.DrawRectangle(hoverBackgroundPen, boxRect);
                        g.FillRectangle(hoverBackgroundBrush, boxRect);
                        g.DrawString(
                            this.TabPages[i].Text,
                            this.Font,
                            hoverTextBrush,
                            textRect,
                            centerNearFormat);
                    }
                    else
                    {
                        //
                        // Draw inactive tab.
                        //
                        g.DrawString(
                            this.TabPages[i].Text,
                            this.Font,
                            inactiveTextBrush,
                            textRect,
                            centerNearFormat);
                    }
                }
            }
        }