TabRenderer TabRenderer TabRenderer TabRenderer Class

정의

비주얼 스타일을 사용하여 tab 컨트롤을 렌더링하는 데 사용되는 메서드를 제공합니다.Provides methods used to render a tab control with visual styles. 이 클래스는 상속될 수 없습니다.This class cannot be inherited.

public ref class TabRenderer sealed
public sealed class TabRenderer
type TabRenderer = class
Public NotInheritable Class TabRenderer
상속
TabRendererTabRendererTabRendererTabRenderer

예제

다음 코드 예제를 사용 하는 사용자 지정 컨트롤을 만드는 방법을 보여 줍니다 합니다 DrawTabPageDrawTabItem 메서드를 두 개의 탭을 사용 하 여 기본 탭 컨트롤을 그립니다.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());
}

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();
        }
    }
}
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

설명

합니다 TabRenderer 클래스의 집합을 제공 static 운영 체제의 현재 비주얼 스타일을 사용 하 여 tab 컨트롤을 렌더링 하는 방법입니다.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. 사용 하는 tab 컨트롤을 그리려면 합니다 DrawTabPage 페이지, 그리고 사용 하는 메서드는 DrawTabItem 각 탭을 그리는 방법.To draw a tab control, use the DrawTabPage method to draw the page, and use the DrawTabItem method to draw each tab.

운영 체제에서 비주얼 스타일을 사용 하 고 애플리케이션 창의 클라이언트 영역에 비주얼 스타일을 적용 하는 경우이 클래스의 메서드는 현재 비주얼 스타일을 사용 하 여 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. 이 클래스의 속성과 메서드를 throw 하는 고, 그렇지는 InvalidOperationException합니다.Otherwise, the methods and properties of this class will throw an InvalidOperationException. 이 클래스의 멤버를 사용할 수 있는지 여부를 확인 하려면 값을 확인 합니다 IsSupported 속성입니다.To determine whether the members of this class can be used, check the value of the IsSupported property.

이 클래스의 함수를 래핑하는 System.Windows.Forms.VisualStyles.VisualStyleRenderer 에서 노출 한 요소 중 하나에 설정 된는 System.Windows.Forms.VisualStyles.VisualStyleElement.Tab 클래스입니다.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.

속성

IsSupported IsSupported IsSupported IsSupported

TabRenderer 클래스를 사용하여 비주얼 스타일로 tab 컨트롤을 그릴 수 있는지 여부를 나타내는 값을 가져옵니다.Gets a value indicating whether the TabRenderer class can be used to draw a tab control with visual styles.

메서드

DrawTabItem(Graphics, Rectangle, Boolean, TabItemState) DrawTabItem(Graphics, Rectangle, Boolean, TabItemState) DrawTabItem(Graphics, Rectangle, Boolean, TabItemState) DrawTabItem(Graphics, Rectangle, Boolean, TabItemState)

지정된 상태, 범위 및 포커스 영역(선택 사항)을 사용하여 탭을 그립니다.Draws a tab in the specified state and bounds, and with an optional focus rectangle.

DrawTabItem(Graphics, Rectangle, Image, Rectangle, Boolean, TabItemState) DrawTabItem(Graphics, Rectangle, Image, Rectangle, Boolean, TabItemState) DrawTabItem(Graphics, Rectangle, Image, Rectangle, Boolean, TabItemState) 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) DrawTabItem(Graphics, Rectangle, String, Font, Boolean, TabItemState) DrawTabItem(Graphics, Rectangle, String, Font, Boolean, TabItemState) 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, Image, Rectangle, Boolean, TabItemState) DrawTabItem(Graphics, Rectangle, String, Font, Image, Rectangle, Boolean, TabItemState) DrawTabItem(Graphics, Rectangle, String, Font, Image, Rectangle, Boolean, TabItemState) 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, TabItemState) DrawTabItem(Graphics, Rectangle, String, Font, TabItemState) DrawTabItem(Graphics, Rectangle, String, Font, TabItemState) DrawTabItem(Graphics, Rectangle, String, Font, TabItemState)

지정된 상태, 범위 및 텍스트를 사용하여 탭을 그립니다.Draws a tab in the specified state and bounds, and with the specified text.

DrawTabItem(Graphics, Rectangle, String, Font, TextFormatFlags, Boolean, TabItemState) DrawTabItem(Graphics, Rectangle, String, Font, TextFormatFlags, Boolean, TabItemState) DrawTabItem(Graphics, Rectangle, String, Font, TextFormatFlags, Boolean, TabItemState) 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, TextFormatFlags, Image, Rectangle, Boolean, TabItemState) DrawTabItem(Graphics, Rectangle, String, Font, TextFormatFlags, Image, Rectangle, Boolean, TabItemState) DrawTabItem(Graphics, Rectangle, String, Font, TextFormatFlags, Image, Rectangle, Boolean, TabItemState) 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.

DrawTabItem(Graphics, Rectangle, TabItemState) DrawTabItem(Graphics, Rectangle, TabItemState) DrawTabItem(Graphics, Rectangle, TabItemState) DrawTabItem(Graphics, Rectangle, TabItemState)

지정된 상태와 범위를 사용하여 탭을 그립니다.Draws a tab in the specified state and bounds.

DrawTabPage(Graphics, Rectangle) DrawTabPage(Graphics, Rectangle) DrawTabPage(Graphics, Rectangle) DrawTabPage(Graphics, Rectangle)

지정된 범위를 사용하여 탭 페이지를 그립니다.Draws a tab page in the specified bounds.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(Inherited from Object)

적용 대상

추가 정보