GroupBoxRenderer 클래스

정의

비주얼 스타일을 사용하거나 사용하지 않고 그룹 상자 컨트롤을 렌더링하는 데 사용되는 메서드를 제공합니다. 이 클래스는 상속될 수 없습니다.

public ref class GroupBoxRenderer sealed
public ref class GroupBoxRenderer abstract sealed
public sealed class GroupBoxRenderer
public static class GroupBoxRenderer
type GroupBoxRenderer = class
Public NotInheritable Class GroupBoxRenderer
Public Class GroupBoxRenderer
상속
GroupBoxRenderer

예제

다음 코드 예제를 사용 하는 사용자 지정 컨트롤을 만드는 방법을 보여 줍니다는 DrawGroupBox 비주얼 스타일이 활성화 된 경우 이중 테두리가 있는 그룹 상자를 그리는 방법입니다.

#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 GroupBoxRendererSample
{
    public ref class CustomGroupBox : public Control
    {
    private:
        Rectangle innerRectangle;
    private:
        GroupBoxState state;
    private:
        FlowLayoutPanel^ panel;

    public:
        CustomGroupBox() : Control()
        {
            innerRectangle = Rectangle();
            state = GroupBoxState::Normal;
            panel = gcnew FlowLayoutPanel();

            this->Size = System::Drawing::Size(200, 200);
            this->Location = Point(10, 10);
            this->Controls->Add(panel);
            this->Text = "CustomGroupBox";
            this->Font = SystemFonts::IconTitleFont;

            innerRectangle.X = ClientRectangle.X + 5;
            innerRectangle.Y = ClientRectangle.Y + 15;
            innerRectangle.Width = ClientRectangle.Width - 10;
            innerRectangle.Height = ClientRectangle.Height - 20;

            panel->FlowDirection = FlowDirection::TopDown;
            panel->Location = Point(innerRectangle.X + 5,
                innerRectangle.Y + 5);
            panel->Size = System::Drawing::Size(innerRectangle.Width - 10,
                innerRectangle.Height - 10);
        }

        // Draw the group box in the current state.
    protected:
        virtual void OnPaint(PaintEventArgs^ e) override 
        {
            __super::OnPaint(e);

            GroupBoxRenderer::DrawGroupBox(e->Graphics, ClientRectangle,
                this->Text, this->Font, state);

            // Draw an additional inner border if visual styles are enabled.
            if (Application::RenderWithVisualStyles)
            {
                GroupBoxRenderer::DrawGroupBox(e->Graphics, innerRectangle,
                    state);
            }
        }

        // Pass added controls to the internal FlowLayoutPanel.
    protected:
        virtual void OnControlAdded(ControlEventArgs^ e) override
        {
            __super::OnControlAdded(e);

            // Ensure that you do not add the panel itself.
            if (e->Control != this->panel)
            {
                this->Controls->Remove(e->Control);
                panel->Controls->Add(e->Control);
            }
        }
    };

    ref class Form1 : public Form
    {
    public:
        Form1() : Form()
        {
            CustomGroupBox^ groupBox1 = gcnew CustomGroupBox();
            groupBox1->Text = "Radio Button Display";
            Controls->Add(groupBox1);

            // Add some radio buttons to test the CustomGroupBox.
            int count = 8;
            array<RadioButton^>^ buttonArray = 
                gcnew array<RadioButton^>(count);
            for (int i = 0; i < count; i++)
            {
                buttonArray[i] = gcnew RadioButton();
                buttonArray[i]->Text = "Button " + (i + 1).ToString();
                groupBox1->Controls->Add(buttonArray[i]);
            }

            if (Application::RenderWithVisualStyles)
            {
                this->Text = "Visual Styles Enabled";
            }
            else
            {
                this->Text = "Visual Styles Disabled";
            }
        }
    };
}

[STAThread]
int main()
{
    // If you do not call EnableVisualStyles below, then
    // GroupBoxRenderer automatically detects this and draws
    // the group box without visual styles.
    Application::EnableVisualStyles();
    Application::Run(gcnew GroupBoxRendererSample::Form1());
}
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace GroupBoxRendererSample
{
    class Form1 : Form
    {
        private Button button1;
    
        public Form1()
            : base()
        {
            CustomGroupBox GroupBox1 = new CustomGroupBox();
            button1 = new Button();
             
            GroupBox1.Text = "Radio Button Display";
            this.button1.Location = new System.Drawing.Point(205, 231);
            this.button1.Size = new System.Drawing.Size(105, 23);
            this.button1.Text = "Toggle Visual Styles";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            Controls.Add(GroupBox1);
            this.Controls.Add(this.button1);

            // Add some radio buttons to test the CustomGroupBox.
            int count = 8;
            RadioButton[] ButtonArray = new RadioButton[count];
            for (int i = 0; i < count; i++)
            {
                ButtonArray[i] = new RadioButton();
                ButtonArray[i].Text = "Button " + (i + 1).ToString();
                GroupBox1.Controls.Add(ButtonArray[i]);
            }

            if (Application.RenderWithVisualStyles)
                this.Text = "Visual Styles Enabled";
            else
                this.Text = "Visual Styles Disabled";
        }

        [STAThread]
        static void Main()
        {
            // If you do not call EnableVisualStyles below, then 
            // GroupBoxRenderer automatically detects this and draws
            // the group box without visual styles.
            Application.EnableVisualStyles();
            Application.Run(new Form1());
        }


    // Match application style and toggle visual styles off
    // and on for the application.
        private void button1_Click(object sender, EventArgs e)
        {
            GroupBoxRenderer.RenderMatchingApplicationState = true;
            Application.VisualStyleState = 
                Application.VisualStyleState ^ 
                VisualStyleState.ClientAndNonClientAreasEnabled;

            if (Application.RenderWithVisualStyles)
                this.Text = "Visual Styles Enabled";
            else
                this.Text = "Visual Styles Disabled";
        }
    }

    public class CustomGroupBox : Control
    {
        private Rectangle innerRectangle = new Rectangle();
        private GroupBoxState state = GroupBoxState.Normal;
        private FlowLayoutPanel panel = new FlowLayoutPanel();

        public CustomGroupBox()
            : base()
        {
            this.Size = new Size(200, 200);
            this.Location = new Point(10, 10);
            this.Controls.Add(panel);
            this.Text = "CustomGroupBox";
            this.Font = SystemFonts.IconTitleFont;

            innerRectangle.X = ClientRectangle.X + 5;
            innerRectangle.Y = ClientRectangle.Y + 15;
            innerRectangle.Width = ClientRectangle.Width - 10;
            innerRectangle.Height = ClientRectangle.Height - 20;

            panel.FlowDirection = FlowDirection.TopDown;
            panel.Location = new Point(innerRectangle.X + 5,
                innerRectangle.Y + 5);
            panel.Size = new Size(innerRectangle.Width - 10,
                innerRectangle.Height - 10);
        }

        // Draw the group box in the current state.
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            GroupBoxRenderer.DrawGroupBox(e.Graphics, ClientRectangle,
                this.Text, this.Font, state);

            // Draw an additional inner border if visual styles are enabled.
            if (Application.RenderWithVisualStyles)
            {
                GroupBoxRenderer.DrawGroupBox(e.Graphics, innerRectangle, state);
            }
        }

        // Pass added controls to the internal FlowLayoutPanel.
        protected override void OnControlAdded(ControlEventArgs e)
        {
            base.OnControlAdded(e);

            // Ensure that you do not add the panel itself.
            if (e.Control != this.panel)
            {
                this.Controls.Remove(e.Control);
                panel.Controls.Add(e.Control);
            }
        }
    }
}
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.VisualStyles



Class Form1
    Inherits Form
    Private WithEvents button1 As Button
    
    
    Public Sub New() 
        Dim GroupBox1 As New CustomGroupBox()
        button1 = New Button()
        
        GroupBox1.Text = "Radio Button Display"
        Me.button1.Location = New System.Drawing.Point(185, 231)
        Me.button1.Size = New System.Drawing.Size(105, 23)
        Me.button1.Text = "Toggle Visual Styles"

        Controls.Add(GroupBox1)
        Me.Controls.Add(Me.button1)
        
        ' Add some radio buttons to test the CustomGroupBox.
        Dim count As Integer = 8
        Dim ButtonArray(count) As RadioButton
        For i = 0 To count - 1
            ButtonArray(i) = New RadioButton()
            ButtonArray(i).Text = "Button " +(i + 1).ToString()
            GroupBox1.Controls.Add(ButtonArray(i))
        Next
        
        If Application.RenderWithVisualStyles Then
            Me.Text = "Visual Styles Enabled"
        Else
            Me.Text = "Visual Styles Disabled"
        End If
    
    End Sub
     
    <STAThread()>  _
    Shared Sub Main() 
        ' If you do not call EnableVisualStyles below, then 
        ' GroupBoxRenderer automatically detects this and draws
        ' the group box without visual styles.
        Application.EnableVisualStyles()
        Application.Run(New Form1())
    
    End Sub
    
    
    ' Match application style and toggle visual styles off
    ' and on for the application.
    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
        Handles button1.Click

        GroupBoxRenderer.RenderMatchingApplicationState = True

        Application.VisualStyleState = _
            Application.VisualStyleState Xor _
            VisualStyleState.ClientAndNonClientAreasEnabled

        If Application.RenderWithVisualStyles Then
            Me.Text = "Visual Styles Enabled"
        Else
            Me.Text = "Visual Styles Disabled"
        End If

    End Sub
End Class


Public Class CustomGroupBox
    Inherits Control
    Private innerRectangle As New Rectangle()
    Private state As GroupBoxState = GroupBoxState.Normal
    Private panel As New FlowLayoutPanel()
    
    
    Public Sub New() 
        Me.Size = New Size(200, 200)
        Me.Location = New Point(10, 10)
        Me.Controls.Add(panel)
        Me.Text = "CustomGroupBox"
        Me.Font = SystemFonts.IconTitleFont
        
        innerRectangle.X = ClientRectangle.X + 5
        innerRectangle.Y = ClientRectangle.Y + 15
        innerRectangle.Width = ClientRectangle.Width - 10
        innerRectangle.Height = ClientRectangle.Height - 20
        
        panel.FlowDirection = FlowDirection.TopDown
        panel.Location = New Point(innerRectangle.X + 5, innerRectangle.Y + 5)
        panel.Size = New Size(innerRectangle.Width - 10, innerRectangle.Height - 10)
    
    End Sub
    
    
    ' Draw the group box in the current state.
    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) 
        MyBase.OnPaint(e)
        
        GroupBoxRenderer.DrawGroupBox(e.Graphics, ClientRectangle, Me.Text, Me.Font, state)
        
        ' Draw an additional inner border if visual styles are enabled.
        If Application.RenderWithVisualStyles Then
            GroupBoxRenderer.DrawGroupBox(e.Graphics, innerRectangle, state)
        End If
    
    End Sub
    
    ' Pass added controls to the internal FlowLayoutPanel.
    Protected Overrides Sub OnControlAdded(ByVal e As ControlEventArgs) 
        MyBase.OnControlAdded(e)
        
        ' Ensure that you do not add the panel itself.
        If e.Control IsNot Me.panel Then
            Me.Controls.Remove(e.Control)
            panel.Controls.Add(e.Control)
        End If
    
    End Sub
End Class

설명

합니다 GroupBoxRenderer 클래스의 집합을 제공 static 메서드 그룹을 렌더링 하는 box 컨트롤입니다. 컨트롤 렌더링이란 컨트롤의 사용자 인터페이스를 그리는 것을 말합니다. 그룹 상자를 그릴 중 하나를 사용 합니다 DrawGroupBox 메서드. 이러한 메서드는 다양 한 텍스트 그리기 옵션을 제공합니다.

운영 체제에서 비주얼 스타일을 사용 하 고 현재 애플리케이션에 비주얼 스타일을 적용 하는 경우 DrawGroupBox 는 현재 비주얼 스타일을 사용 하 여 그룹 상자를 그립니다. 그렇지 않으면 DrawGroupBox 그룹 상자의 Windows 클래식 스타일으로 그려집니다. 운영 체제의 현재 비주얼 스타일 설정을 자동으로 일치 해야 하는 사용자 지정 컨트롤을 그리는 경우에 유용 합니다.

이 클래스의 함수를 래핑하는 System.Windows.Forms.VisualStyles.VisualStyleRenderer 에서 노출 한 요소 중 하나에 설정 된는 System.Windows.Forms.VisualStyles.VisualStyleElement.Button.GroupBox 클래스입니다. 자세한 내용은 비주얼 스타일을 사용 하 여 컨트롤 렌더링합니다.

속성

RenderMatchingApplicationState

렌더러에서 애플리케이션 상태를 사용하여 렌더링 스타일을 결정하는지 여부를 나타내는 값을 가져오거나 설정합니다.

메서드

DrawGroupBox(Graphics, Rectangle, GroupBoxState)

지정된 상태와 범위로 그룹 상자 컨트롤을 그립니다.

DrawGroupBox(Graphics, Rectangle, String, Font, Color, GroupBoxState)

지정된 텍스트, 글꼴 및 색을 사용하여 지정된 상태와 범위로 그룹 상자 컨트롤을 그립니다.

DrawGroupBox(Graphics, Rectangle, String, Font, Color, TextFormatFlags, GroupBoxState)

지정된 텍스트, 글꼴, 색 및 텍스트 서식을 사용하여 지정된 상태와 범위로 그룹 상자 컨트롤을 그립니다.

DrawGroupBox(Graphics, Rectangle, String, Font, GroupBoxState)

지정된 텍스트와 글꼴을 사용하여 지정된 상태와 범위로 그룹 상자 컨트롤을 그립니다.

DrawGroupBox(Graphics, Rectangle, String, Font, TextFormatFlags, GroupBoxState)

지정된 텍스트, 글꼴 및 텍스트 서식을 사용하여 지정된 상태와 범위로 그룹 상자 컨트롤을 그립니다.

DrawParentBackground(Graphics, Rectangle, Control)

지정된 영역에 컨트롤 부모의 배경을 그립니다.

IsBackgroundPartiallyTransparent(GroupBoxState)

그룹 상자의 배경에 반투명 또는 알파가 혼합된 부분이 있는지 여부를 나타냅니다.

적용 대상

추가 정보