TabRendererとは? わかりやすく解説

TabRenderer クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

visual スタイルを使用してタブ コントロールをレンダリングするメソッドを用意します。このクラスは継承できません。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public NotInheritable Class
 TabRenderer
public sealed class TabRenderer
public ref class TabRenderer sealed
public final class TabRenderer
解説解説

TabRenderer クラスには、オペレーティング システムの現在の visual スタイルを使用してタブ コントロールをレンダリングするために使用できる一連の static メソッドが用意されています。コントロールのレンダリングとは、コントロールのユーザー インターフェイスを描画することです。現在の visual スタイルの外観を持つカスタム コントロールを描画する場合に有用です。タブ コントロールを描画するには、DrawTabPage メソッドを使用してページを描画し、DrawTabItem メソッドを使用して各タブを描画します。

オペレーティング システムで visual スタイルが有効にされており、visual スタイルがアプリケーション ウィンドウのクライアント領域に適用されている場合、このクラスのメソッドは現在の visual スタイルを使用してタブ コントロールを描画します。それ以外の場合は、このクラスのメソッドとプロパティは InvalidOperationException をスローします。このクラスのメンバを使用できるかどうかを確認するには、IsSupported プロパティの値をチェックします。

このクラスは、System.Windows.Forms.VisualStyles.VisualStyleElement.Tab クラスが公開する要素のいずれかに設定された System.Windows.Forms.VisualStyles.VisualStyleRenderer の機能をラップします。詳細については、「visual スタイルが使用されているコントロールのレンダリング」を参照してください。

Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 プラットフォームメモ : visual スタイルは、これらのプラットフォームでのみサポートされます。

使用例使用例

DrawTabPage メソッドおよび DrawTabItem メソッドを使用して、2 つのタブがある基本的なタブ コントロールを描画するカスタム コントロールを作成する方法を次のコード例に示します。

Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.VisualStyles

Namespace TabRendererSample

    Class Form1
        Inherits Form

        Public Sub New()
            Dim Tab1 As New
 CustomTabControl()
            Controls.Add(Tab1)
            Me.Size = New Size(500, 500)
        End Sub

        <STAThread()> _
        Shared Sub 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(New Form1())
        End Sub
    End Class

    Public Class CustomTabControl
        Inherits Control

        Private tabPageRectangle As Rectangle
        Private tabItemRectangle1 As Rectangle
        Private tabItemRectangle2 As Rectangle
        Private tabHeight As Integer
 = 30
        Private tabWidth As Integer
 = 100
        Private tab1State As TabItemState =
 TabItemState.Selected
        Private tab2State As TabItemState =
 TabItemState.Normal
        Private tab1Text As String
 = "Tab 1"
        Private tab2Text As String
 = "Tab 2"
        Private tab1Focused As Boolean
 = True
        Private tab2Focused As Boolean
 = False

        Public Sub New()
            With Me
                .Size = New Size(300, 300)
                .Location = New Point(10, 10)
                .Font = SystemFonts.IconTitleFont
                .Text = "TabRenderer"
                .DoubleBuffered = True
            End With

            tabPageRectangle = New 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 = New Rectangle(ClientRectangle.X,
 _
                ClientRectangle.Y, tabWidth, tabHeight + 2)

            tabItemRectangle2 = New Rectangle(ClientRectangle.Location.X
 + _
                tabWidth, ClientRectangle.Location.Y, tabWidth, tabHeight)
        End Sub

        ' Draw the tab page and the tab items.
        Protected Overrides Sub
 OnPaint(ByVal e As PaintEventArgs)
            MyBase.OnPaint(e)

            If Not TabRenderer.IsSupported
 Then
                Me.Parent.Text = "CustomTabControl
 Disabled"
                Return
            End If

            TabRenderer.DrawTabPage(e.Graphics, tabPageRectangle)
            TabRenderer.DrawTabItem(e.Graphics, tabItemRectangle1, _
                tab1Text, Me.Font, tab1Focused, tab1State)
            TabRenderer.DrawTabItem(e.Graphics, tabItemRectangle2, _
                tab2Text, Me.Font, tab2Focused, tab2State)
            Me.Parent.Text = "CustomTabControl
 Enabled"
        End Sub

        ' Draw the selected tab item.
        Protected Overrides Sub
 OnMouseDown(ByVal e As MouseEventArgs)
            MyBase.OnMouseDown(e)

            If Not TabRenderer.IsSupported
 Then
                Return
            End If

            ' 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) Then
                tab1State = TabItemState.Selected
                tab2State = TabItemState.Normal
                tabItemRectangle1.Height += 2
                tabItemRectangle2.Height -= 2
                tab1Focused = True
                tab2Focused = False
            End If

            ' The second tab is clicked.
            If tabItemRectangle2.Contains(e.Location) Then
                tab2State = TabItemState.Selected
                tab1State = TabItemState.Normal
                tabItemRectangle2.Height += 2
                tabItemRectangle1.Height -= 2
                tab2Focused = True
                tab1Focused = False
            End If

            Invalidate()
        End Sub

    End Class
End Namespace
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();
            Controls.Add(Tab1);
            this.Size = new Size(500, 500);
        }

        [STAThread]
        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.EnableVisualStyles();
            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.Width,
                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)
        {
            base.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 override void OnMouseDown(MouseEventArgs
 e)
        {
            base.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();
        }
    }
}
#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());
}

継承階層継承階層
System.Object
  System.Windows.Forms.TabRenderer
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TabRenderer メンバ
System.Windows.Forms 名前空間
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement

TabRenderer プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

TabRenderer クラス
System.Windows.Forms 名前空間
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement

TabRenderer メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

TabRenderer クラス
System.Windows.Forms 名前空間
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement

TabRenderer メンバ

visual スタイルを使用してタブ コントロールをレンダリングするメソッドを用意します。このクラスは継承できません。

TabRenderer データ型で公開されるメンバを以下の表に示します。


パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

TabRenderer クラス
System.Windows.Forms 名前空間
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「TabRenderer」の関連用語

TabRendererのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TabRendererのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS