TabRenderer Class

Note: This class is new in the .NET Framework version 2.0.

Provides methods used to render a tab control with visual styles. This class cannot be inherited.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in

public sealed class TabRenderer
public final class TabRenderer
public final class TabRenderer

The TabRenderer class provides a set of static methods that can be used to render a tab control with the current visual style of the operating system. Rendering a control refers to drawing the user interface of a control. This is useful if you are drawing a custom control that should have the appearance of the current visual style. To draw a tab control, use the DrawTabPage method to draw the page, and use the DrawTabItem method to draw each tab.

If visual styles are enabled in the operating system and visual styles are applied to the client area of application windows, the methods of this class will draw the tab control with the current visual style. Otherwise, the methods and properties of this class will throw an InvalidOperationException. To determine whether the members of this class can be used, check the value of the IsSupported property.

This class wraps the functionality of a System.Windows.Forms.VisualStyles.VisualStyleRenderer that is set to one of the elements exposed by the System.Windows.Forms.VisualStyles.VisualStyleElement.Tab class. For more information, see Rendering Controls with Visual Styles.

Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 Platform Note: Visual styles are supported only on these platforms.

The following code example demonstrates how to create a custom control that uses the DrawTabPage and DrawTabItem methods to draw a basic tab control with two tabs.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace TabRendererSample
    class Form1 : Form
        public Form1()
            : base()
            CustomTabControl Tab1 = new CustomTabControl();
            this.Size = new Size(500, 500);

        static void Main()
            // The call to EnableVisualStyles below does not affect whether 
            // TabRenderer.IsSupported is true; as long as visual styles 
            // are enabled by the operating system, IsSupported is true.
            Application.Run(new Form1());

    public class CustomTabControl : Control
        private Rectangle tabPageRectangle;
        private Rectangle tabItemRectangle1;
        private Rectangle tabItemRectangle2;
        private int tabHeight = 30;
        private int tabWidth = 100;
        private TabItemState tab1State = TabItemState.Selected;
        private TabItemState tab2State = TabItemState.Normal;
        private string tab1Text = "Tab 1";
        private string tab2Text = "Tab 2";
        private bool tab1Focused = true;
        private bool tab2Focused = false;

        public CustomTabControl()
            : base()
            this.Size = new Size(300, 300);
            this.Location = new Point(10, 10);
            this.Font = SystemFonts.IconTitleFont;
            this.Text = "TabRenderer";
            this.DoubleBuffered = true;

            tabPageRectangle = new Rectangle(ClientRectangle.X,
                ClientRectangle.Y + tabHeight,
                ClientRectangle.Height - tabHeight);

            // Extend the first tab rectangle down by 2 pixels, 
            // because it is selected by default.
            tabItemRectangle1 = new Rectangle(ClientRectangle.X,
                ClientRectangle.Y, tabWidth, tabHeight + 2);

            tabItemRectangle2 = new Rectangle(ClientRectangle.Location.X +
                tabWidth, ClientRectangle.Location.Y, tabWidth, tabHeight);

        // Draw the tab page and the tab items.
        protected override void OnPaint(PaintEventArgs e)

            if (!TabRenderer.IsSupported)
                this.Parent.Text = "CustomTabControl Disabled";

            TabRenderer.DrawTabPage(e.Graphics, tabPageRectangle);
            TabRenderer.DrawTabItem(e.Graphics, tabItemRectangle1,
                tab1Text, this.Font, tab1Focused, tab1State);
            TabRenderer.DrawTabItem(e.Graphics, tabItemRectangle2,
                tab2Text, this.Font, tab2Focused, tab2State);

            this.Parent.Text = "CustomTabControl Enabled";

        // Draw the selected tab item.
        protected override void OnMouseDown(MouseEventArgs e)

            if (!TabRenderer.IsSupported)

            // The first tab is clicked. Note that the height of the 
            // selected tab rectangle is raised by 2, so that it draws 
            // over the border of the tab page.
            if (tabItemRectangle1.Contains(e.Location))
                tab1State = TabItemState.Selected;
                tab2State = TabItemState.Normal;
                tabItemRectangle1.Height += 2;
                tabItemRectangle2.Height -= 2;
                tab1Focused = true;
                tab2Focused = false;

            // The second tab is clicked.
            if (tabItemRectangle2.Contains(e.Location))
                tab2State = TabItemState.Selected;
                tab1State = TabItemState.Normal;
                tabItemRectangle2.Height += 2;
                tabItemRectangle1.Height -= 2;
                tab2Focused = true;
                tab1Focused = false;



Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions