Exemple #1
0
        /// <include file='doc\TabPage.uex' path='docs/doc[@for="TabPage.OnPaintBackground"]/*' />
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            // Utilize the TabRenderer new to Whidbey to draw the tab pages so that the
            // panels are drawn using the correct visual styles when the application supports using visual
            // styles.

            // Does this application utilize Visual Styles?
            // Utilize the UseVisualStyleBackColor property to determine whether or
            // not the themed background should be utilized.
            TabControl parent = ParentInternal as TabControl;

            if (Application.RenderWithVisualStyles && UseVisualStyleBackColor && (parent != null && parent.Appearance == TabAppearance.Normal))
            {
                Color     bkcolor     = UseVisualStyleBackColor ? Color.Transparent : this.BackColor;
                Rectangle inflateRect = LayoutUtils.InflateRect(DisplayRectangle, Padding);



                //To ensure that the tabpage draws correctly (the border will get clipped and
                // and gradient fill will match correctly with the tabcontrol).  Unfortunately, there is no good way to determine
                // the padding used on the tabpage.
                // I would like to use the following below, but GetMargins is busted in the theming API:
                //VisualStyleRenderer visualStyleRenderer = new VisualStyleRenderer(VisualStyleElement.Tab.Pane.Normal);
                //Padding themePadding = visualStyleRenderer.GetMargins(e.Graphics, MarginProperty.ContentMargins);
                //Rectangle rectWithBorder = new Rectangle(inflateRect.X - themePadding.Left,
                //    inflateRect.Y - themePadding.Top,
                //    inflateRect.Width + themePadding.Right + themePadding.Left,
                //    inflateRect.Height + themePadding.Bottom + themePadding.Top);
                Rectangle rectWithBorder = new Rectangle(inflateRect.X - 4, inflateRect.Y - 2, inflateRect.Width + 8, inflateRect.Height + 6);

                TabRenderer.DrawTabPage(e.Graphics, rectWithBorder);

                // Is there a background image to paint? The TabRenderer does not currently support
                // painting the background image on the panel, so we need to draw it ourselves.
                if (this.BackgroundImage != null)
                {
                    ControlPaint.DrawBackgroundImage(e.Graphics, BackgroundImage, bkcolor, BackgroundImageLayout, inflateRect, inflateRect, DisplayRectangle.Location);
                }
            }
            else
            {
                base.OnPaintBackground(e);
            }
        }
Exemple #2
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            TabControl parentInternal = this.ParentInternal as TabControl;

            if ((Application.RenderWithVisualStyles && this.UseVisualStyleBackColor) && ((parentInternal != null) && (parentInternal.Appearance == TabAppearance.Normal)))
            {
                Color     backColor  = this.UseVisualStyleBackColor ? Color.Transparent : this.BackColor;
                Rectangle bounds     = LayoutUtils.InflateRect(this.DisplayRectangle, base.Padding);
                Rectangle rectangle2 = new Rectangle(bounds.X - 4, bounds.Y - 2, bounds.Width + 8, bounds.Height + 6);
                TabRenderer.DrawTabPage(e.Graphics, rectangle2);
                if (this.BackgroundImage != null)
                {
                    ControlPaint.DrawBackgroundImage(e.Graphics, this.BackgroundImage, backColor, this.BackgroundImageLayout, bounds, bounds, this.DisplayRectangle.Location);
                }
            }
            else
            {
                base.OnPaintBackground(e);
            }
        }