GroupBoxRenderer GroupBoxRenderer GroupBoxRenderer GroupBoxRenderer Class

定義

visual スタイルを使用して、または使用せずに、グループ ボックス コントロールをレンダリングするために使用されるメソッドを提供します。Provides methods used to render a group box control with or without visual styles. このクラスは継承できません。This class cannot be inherited.

public ref class GroupBoxRenderer sealed
public sealed class GroupBoxRenderer
type GroupBoxRenderer = class
Public NotInheritable Class GroupBoxRenderer
継承
GroupBoxRendererGroupBoxRendererGroupBoxRendererGroupBoxRenderer

次のコード例は、使用するカスタム コントロールを作成する方法を示します、 DrawGroupBox visual スタイルが有効になっている場合は、二重線付きのグループ ボックスを描画するメソッド。The following code example demonstrates how to create a custom control that uses the DrawGroupBox method to draw a group box with a double border if visual styles are enabled.

#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
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
        Dim i As Integer
        For i = 0 To count
            ButtonArray(i) = New RadioButton()
            ButtonArray(i).Text = "Button " +(i + 1).ToString()
            GroupBox1.Controls.Add(ButtonArray(i))
        Next i
        
        If Application.RenderWithVisualStyles Then
            Me.Text = "Visual Styles Enabled"
        Else
            Me.Text = "Visual Styles Disabled"
        End If
    
    End Sub 'New
     
    <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 'Main
    
    
    ' 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 'New
    
    
    ' 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 'OnPaint
    
    ' 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 'OnControlAdded
End Class 'CustomGroupBox

注釈

GroupBoxRendererクラスのセットを提供するstaticボックス コントロールのグループを表示するために使用できるメソッド。The GroupBoxRenderer class provides a set of static methods that can be used to render a group box control. コントロールのレンダリングとは、コントロールのユーザー インターフェイスを描画することを意味します。Rendering a control refers to drawing the user interface of a control. グループ ボックスを描画するのいずれかの操作を使用して、DrawGroupBoxメソッド。To draw a group box, use one of the DrawGroupBox methods. これらのメソッドは、さまざまなテキストの描画オプションを提供します。These methods provide a variety of text drawing options.

オペレーティング システムで visual スタイルが有効になっていて、現在のアプリケーションに visual スタイルが適用DrawGroupBox現在の visual スタイルでグループ ボックスを描画します。If visual styles are enabled in the operating system and visual styles are applied to the current application, DrawGroupBox will draw the group box with the current visual style. それ以外の場合、DrawGroupBox従来の Windows スタイルでグループ ボックスを描画します。Otherwise, DrawGroupBox will draw the group box with the classic Windows style. これは、オペレーティング システムの現在の visual スタイルの設定を自動的に一致する必要があるカスタム コントロールを描画する場合に便利です。This is useful if you are drawing a custom control that should automatically match the current visual style setting of the operating system.

このクラスの機能をラップする、System.Windows.Forms.VisualStyles.VisualStyleRendererによって公開されている要素のいずれかに設定されている、System.Windows.Forms.VisualStyles.VisualStyleElement.Button.GroupBoxクラス。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.Button.GroupBox class. 詳細については、次を参照してください。 Visual スタイルを使用しているコントロールのレンダリングします。For more information, see Rendering Controls with Visual Styles.

プロパティ

RenderMatchingApplicationState RenderMatchingApplicationState RenderMatchingApplicationState RenderMatchingApplicationState

レンダラーがアプリケーション状態に応じて描画スタイルを決定するかどうかを示す値を取得または設定します。Gets or sets a value indicating whether the renderer uses the application state to determine rendering style.

メソッド

DrawGroupBox(Graphics, Rectangle, GroupBoxState) DrawGroupBox(Graphics, Rectangle, GroupBoxState) DrawGroupBox(Graphics, Rectangle, GroupBoxState) DrawGroupBox(Graphics, Rectangle, GroupBoxState)

指定した状態および境界でグループ ボックス コントロールを描画します。Draws a group box control in the specified state and bounds.

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

指定したテキスト、フォント、および色を使用して、指定した状態および境界でグループ ボックス コントロールを描画します。Draws a group box control in the specified state and bounds, with the specified text, font, and color.

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

指定したテキスト、フォント、色、およびテキストの書式設定を使用して、指定した状態および境界でグループ ボックス コントロールを描画します。Draws a group box control in the specified state and bounds, with the specified text, font, color, and text formatting.

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

指定したテキストとフォントを使用して、指定した状態および境界でグループ ボックス コントロールを描画します。Draws a group box control in the specified state and bounds, with the specified text and font.

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

指定したテキスト、フォント、およびテキストの書式設定を使用して、指定した状態および境界でグループ ボックス コントロールを描画します。Draws a group box control in the specified state and bounds, with the specified text, font, and text formatting.

DrawParentBackground(Graphics, Rectangle, Control) DrawParentBackground(Graphics, Rectangle, Control) DrawParentBackground(Graphics, Rectangle, Control) DrawParentBackground(Graphics, Rectangle, Control)

指定領域にコントロールの親の背景を描画します。Draws the background of a control's parent in the specified area.

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)
IsBackgroundPartiallyTransparent(GroupBoxState) IsBackgroundPartiallyTransparent(GroupBoxState) IsBackgroundPartiallyTransparent(GroupBoxState) IsBackgroundPartiallyTransparent(GroupBoxState)

グループ ボックスの背景の一部が半透明である (アルファ ブレンドされている) かどうかを示します。Indicates whether the background of the group box has any semitransparent or alpha-blended pieces.

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)

適用対象

こちらもご覧ください