TabRenderer Class
Provides methods used to render a tab control with visual styles. This class cannot be inherited.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The TabRenderer type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | IsSupported | Gets a value indicating whether the TabRenderer class can be used to draw a tab control with visual styles. |
| Name | Description | |
|---|---|---|
![]() ![]() | DrawTabItem(Graphics, Rectangle, TabItemState) | Draws a tab in the specified state and bounds. |
![]() ![]() | DrawTabItem(Graphics, Rectangle, Boolean, TabItemState) | Draws a tab in the specified state and bounds, and with an optional focus rectangle. |
![]() ![]() | DrawTabItem(Graphics, Rectangle, String, Font, TabItemState) | Draws a tab in the specified state and bounds, and with the specified text. |
![]() ![]() | DrawTabItem(Graphics, Rectangle, Image, Rectangle, Boolean, TabItemState) | Draws a tab in the specified state and bounds, with the specified image, and with an optional focus rectangle. |
![]() ![]() | DrawTabItem(Graphics, Rectangle, String, Font, Boolean, TabItemState) | Draws a tab in the specified state and bounds, with the specified text, and with an optional focus rectangle. |
![]() ![]() | DrawTabItem(Graphics, Rectangle, String, Font, TextFormatFlags, Boolean, TabItemState) | Draws a tab in the specified state and bounds, with the specified text and text formatting, and with an optional focus rectangle. |
![]() ![]() | DrawTabItem(Graphics, Rectangle, String, Font, Image, Rectangle, Boolean, TabItemState) | Draws a tab in the specified state and bounds, with the specified text and image, and with an optional focus rectangle. |
![]() ![]() | DrawTabItem(Graphics, Rectangle, String, Font, TextFormatFlags, Image, Rectangle, Boolean, TabItemState) | Draws a tab in the specified state and bounds; with the specified text, text formatting, and image; and with an optional focus rectangle. |
![]() ![]() | DrawTabPage | Draws a tab page in the specified bounds. |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
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.Drawing.dll> #using <System.Windows.Forms.dll> #using <System.dll> using namespace System; using namespace System::Drawing; using namespace System::Windows::Forms; using namespace System::Windows::Forms::VisualStyles; namespace TabRendererSample { public ref class CustomTabControl : public Control { private: Rectangle tabPageRectangle; Rectangle tabItemRectangle1; Rectangle tabItemRectangle2; int tabHeight; int tabWidth; TabItemState tab1State; TabItemState tab2State; String^ tab1Text; String^ tab2Text; bool tab1Focused; bool tab2Focused; public: CustomTabControl() { this->tabHeight = 30; this->tabWidth = 100; this->tab1State = TabItemState::Selected; this->tab2State = TabItemState::Normal; this->tab1Text = "Tab 1"; this->tab2Text = "Tab 2"; this->tab1Focused = true; this->tab2Focused = false; this->Size = System::Drawing::Size(300, 300); this->Location = Point(10, 10); this->Font = SystemFonts::IconTitleFont; this->Text = "TabRenderer"; this->DoubleBuffered = true; tabPageRectangle = Rectangle(ClientRectangle.X, ClientRectangle.Y + tabHeight, ClientRectangle.Width, ClientRectangle.Height - tabHeight); // Extend the first tab rectangle down by 2 pixels, // because it is selected by default. tabItemRectangle1 = Rectangle(ClientRectangle.X, ClientRectangle.Y, tabWidth, tabHeight + 2); tabItemRectangle2 = Rectangle(ClientRectangle.Location.X + tabWidth, ClientRectangle.Location.Y, tabWidth, tabHeight); } // Draw the tab page and the tab items. protected: virtual void OnPaint(PaintEventArgs^ e) override { __super::OnPaint(e); if (!TabRenderer::IsSupported) { this->Parent->Text = "CustomTabControl Disabled"; return; } 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: virtual void OnMouseDown(MouseEventArgs^ e) override { __super::OnMouseDown(e); if (!TabRenderer::IsSupported) { return; } // 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; } Invalidate(); } }; public ref class Form1 : public Form { public: Form1() { CustomTabControl^ Tab1 = gcnew CustomTabControl(); Controls->Add(Tab1); this->Size = System::Drawing::Size(500, 500); } }; } [STAThread] int 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::EnableVisualStyles(); Application::Run(gcnew TabRendererSample::Form1()); }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
