PowerTools PlusPak for Windows Forms 8.0J
GcRadioGroupBox クラス
メンバ  使用例 

ラジオボタン項目のグループを表示するWindowsコントロールを表します。
構文
Public Class GcRadioGroupBox 
   Inherits GcGroupBoxControlBase
public class GcRadioGroupBox : GcGroupBoxControlBase 
解説

このクラスはGcGroupBoxControlBaseクラスから継承され、子ラジオボタン項目に関連する特有の機能を実装します。

このクラスにはItemsコレクションがあり、このコレクションを使用して項目を追加または削除したり、GcRadioGroupBoxコントロール内の項目の数を取得したりできます。CheckedItemCheckedIndexは、GcRadioGroupBox内のオンになっているRadioButtonItemを示します。GcRadioGroupBoxコントロールでは、オンにできる項目は1つだけです。また、EnableAllItemsおよびDisableAllItemsを使用すると、すべての項目を有効または無効にできます。

ユーザーがUI操作によって別の項目のラジオボタンをオンにすると、CheckedItemChangedイベントとCheckedIndexChangedイベントが発生します。プログラムによってCheckedItemプロパティまたはCheckedIndexプロパティが変更された場合にも、CheckedItemChangedイベントとCheckedIndexChangedイベントが発生します。項目の境界の中でマウス左ボタンをクリックすると、ItemClickイベントが発生します。

使用例
次のサンプルコードは、GcRadioGroupBoxコントロールのメソッド、プロパティ、およびコレクションの使用方法を示します。これはプロジェクトにコピー&ペーストするだけですぐに実行できる完成したサンプルです。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GrapeCity.Win.Containers;
using System.Collections;

namespace GrapeCity.Win.PlusPak.SampleCodes_CS
{
    public class GcRadioGroupBoxForm : Form
    {
        private GrapeCity.Win.Containers.GcRadioGroupBox gcRadioGroupBox1;
        private Button button1;
        private Label label1;
        private Button button2;
        private ListBox listBox1;
        private CheckBox checkBox1;
        private System.ComponentModel.IContainer components = null;

        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.button2 = new System.Windows.Forms.Button();
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.gcRadioGroupBox1 = new GrapeCity.Win.Containers.GcRadioGroupBox();
            this.checkBox1 = new System.Windows.Forms.CheckBox();
            ((System.ComponentModel.ISupportInitialize)(this.gcRadioGroupBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(211, 44);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(105, 23);
            this.button1.TabIndex = 6;
            this.button1.Text = "Collapse all items";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(211, 17);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(62, 13);
            this.label1.TabIndex = 5;
            this.label1.Text = "Commands:";
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(211, 73);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(105, 23);
            this.button2.TabIndex = 7;
            this.button2.Text = "Disable all items";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // listBox1
            // 
            this.listBox1.FormattingEnabled = true;
            this.listBox1.Location = new System.Drawing.Point(10, 143);
            this.listBox1.Name = "listBox1";
            this.listBox1.Size = new System.Drawing.Size(195, 82);
            this.listBox1.TabIndex = 1;
            // 
            // gcRadioGroupBox1
            // 
            this.gcRadioGroupBox1.Location = new System.Drawing.Point(10, 36);
            this.gcRadioGroupBox1.Name = "gcRadioGroupBox1";
            this.gcRadioGroupBox1.Size = new System.Drawing.Size(155, 101);
            this.gcRadioGroupBox1.TabIndex = 0;
            // 
            // checkBox1
            // 
            this.checkBox1.AutoSize = true;
            this.checkBox1.Location = new System.Drawing.Point(13, 13);
            this.checkBox1.Name = "checkBox1";
            this.checkBox1.Size = new System.Drawing.Size(118, 17);
            this.checkBox1.TabIndex = 8;
            this.checkBox1.Text = "Button Appearance";
            this.checkBox1.UseVisualStyleBackColor = true;
            this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
            // 
            // GcRadioGroupBoxForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(339, 241);
            this.Controls.Add(this.checkBox1);
            this.Controls.Add(this.listBox1);
            this.Controls.Add(this.gcRadioGroupBox1);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.button1);
            this.Name = "GcRadioGroupBoxForm";
            this.Text = "GcRadioGroupBox";
            ((System.ComponentModel.ISupportInitialize)(this.gcRadioGroupBox1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        public GcRadioGroupBoxForm()
        {
            InitializeComponent();

            InitializeGcRadioGroupBox();

            this.DisplayAllItems();
        }

        private void InitializeGcRadioGroupBox()
        {
            // Set header text by setting the Text property.
            this.gcRadioGroupBox1.Text = "&Collapse All";

            // Enable gcRadioGroupBox1 to expand or collapse. 
            this.gcRadioGroupBox1.HeaderType = HeaderType.ExpanderAndText;

            // Create a top-line border radio group box.
            this.gcRadioGroupBox1.GroupStyle = GroupStyle.TopLine;

            // Initialize the layout of items by LayoutSettings.
            this.gcRadioGroupBox1.LayoutSettings.LayoutMode = LayoutMode.Table;
            this.gcRadioGroupBox1.LayoutSettings.Orientation = System.Windows.Forms.Orientation.Vertical;
            this.gcRadioGroupBox1.LayoutSettings.RowCount = 3;
            this.gcRadioGroupBox1.LayoutSettings.HorizontalAdjustment = GrapeCity.Win.Containers.LineAdjustment.Distributed;
            this.gcRadioGroupBox1.LayoutSettings.VerticalAdjustment = GrapeCity.Win.Containers.LineAdjustment.Average;

            this.gcRadioGroupBox1.CheckedItemChanged += 
                new System.EventHandler<CheckedItemChangedEventArgs>(this.gcRadioGroupBox1_CheckedItemChanged);
            this.gcRadioGroupBox1.HeaderStateChange +=
                new System.EventHandler<HeaderStateChangeEventArgs>(this.gcRadioGroupBox1_HeaderStateChange);

            // Create and add some items.
            RadioButtonItem[] items = new RadioButtonItem[] 
            {
                new RadioButtonItem("item1"),
                new RadioButtonItem("item2"),
                new RadioButtonItem("item3"),
                new RadioButtonItem("item4"),
                new RadioButtonItem("item5"),
            };
            this.gcRadioGroupBox1.Items.AddRange(items);
        }

        // Fill listBox1 with all the items in gcRadioGroupBox1.
        private void DisplayAllItems()
        {
            // Display all the items of gcRadioGroupBox1 in list box.
            this.listBox1.Items.Clear();
            RadioButtonItemCollection items = this.gcRadioGroupBox1.Items;
            foreach (RadioButtonItem item in items)
            {
                int index = this.listBox1.Items.Add(
                     item.Text +
                    " index: " + items.IndexOf(item).ToString() +
                    " checked state: " + item.Checked);
            }

            // Select the corresponding item in listBox1.
            this.listBox1.SelectedIndex = this.gcRadioGroupBox1.CheckedIndex;
        }        

        // Click button1 will expand or collapse gcRadioGroupBox1.
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.gcRadioGroupBox1.IsExpanded)
            {
                this.gcRadioGroupBox1.Collapse();
            }
            else
            {
                this.gcRadioGroupBox1.Expand();
            }
            this.UpdateButton1Text();
        }

        // Click button2 will enable or disable all items.
        private void button2_Click(object sender, EventArgs e)
        {
            if (AreAllItemsDisabled)
            {
                this.gcRadioGroupBox1.EnableAllItems();
            }
            else
            {
                this.gcRadioGroupBox1.DisableAllItems();
            }

            // Update button3's text to appropriate value.
            this.UpdateButton2Text();
        }      

        // Update the items for listBox1 when item checked changed in gcRadioGroupBox1,
        private void gcRadioGroupBox1_CheckedItemChanged(object sender, CheckedItemChangedEventArgs e)
        {
            if (e.CurrentCheckedItem != null)
            {
                // Use special styles for checked items.
                e.CurrentCheckedItem.ForeColor = Color.Red;
                e.CurrentCheckedItem.Font = new Font(e.CurrentCheckedItem.Font, FontStyle.Bold);
            }

            if (e.OriginalCheckedItem != null)
            {
                // Reset these properties will cause the properties to retreive their values from gcRadioGroupBox1.
                e.OriginalCheckedItem.ForeColor = Color.Empty;
                e.OriginalCheckedItem.Font = null;
            }

            // Update the items displayed in listBox1.
            this.DisplayAllItems();
        }

        // update the header text when gcRadioGroupBox1's header state is changed.
        private void gcRadioGroupBox1_HeaderStateChange(object sender, HeaderStateChangeEventArgs e)
        {
            this.UpdateHeaderText();
            this.UpdateButton1Text();
        }

        // Update the header text according to the current header type and header state.
        private void UpdateHeaderText()
        {
            if (this.gcRadioGroupBox1.HeaderType == HeaderType.ExpanderAndText)
            {
                if (this.gcRadioGroupBox1.HeaderState == HeaderState.Expanded)
                {
                    this.gcRadioGroupBox1.Text = "&Collapse All";
                }
                else
                {
                    this.gcRadioGroupBox1.Text = "&Expand All";
                }
            }
        }

        // Change the appearance of all items in gcRadioGroupBox1.
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (this.checkBox1.Checked)
            {
                this.gcRadioGroupBox1.ItemSettings.Appearance = Appearance.Button;
            }
            else
            {
                this.gcRadioGroupBox1.ItemSettings.Appearance = Appearance.Normal;
            }
        }

        // Update the button1's text according to whether gcRadioGroupBox1 is expanded.
        private void UpdateButton1Text()
        {
            if (this.gcRadioGroupBox1.IsExpanded)
            {
                this.button1.Text = "Collapse all items";
            }
            else
            {
                this.button1.Text = "Expand all items";
            }
        }

        // Update the button1's text according to whether all items in gcRadioGroupBox1 are enabled.
        private void UpdateButton2Text()
        {
            if (AreAllItemsDisabled)
            {
                this.button2.Text = "Enable all items";
            }
            else
            {
                this.button2.Text = "Disable all items";
            }
        }

        private bool AreAllItemsDisabled
        {
            get
            {
                foreach (RadioButtonItem item in this.gcRadioGroupBox1.Items)
                {
                    if (item.Enabled)
                        return false;
                }
                return true;
            }
        }

        [STAThread]
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new GcRadioGroupBoxForm());
        }
    }

}
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports GrapeCity.Win.Containers
Imports System.Collections

Namespace GrapeCity.Win.PlusPak.SampleCodes_VB
    Public Class GcRadioGroupBoxForm
        Inherits Form
        Private gcRadioGroupBox1 As GcRadioGroupBox
        Private button1 As Button
        Private label1 As Label
        Private button2 As Button
        Private listBox1 As ListBox
        Private checkBox1 As CheckBox
        Private components As System.ComponentModel.IContainer = Nothing

        Private Sub InitializeComponent()
            Me.button1 = New System.Windows.Forms.Button()
            Me.label1 = New System.Windows.Forms.Label()
            Me.button2 = New System.Windows.Forms.Button()
            Me.listBox1 = New System.Windows.Forms.ListBox()
            Me.gcRadioGroupBox1 = New GcRadioGroupBox()
            Me.checkBox1 = New System.Windows.Forms.CheckBox()
            DirectCast((Me.gcRadioGroupBox1), System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            ' 
            ' button1
            ' 
            Me.button1.Location = New System.Drawing.Point(207, 44)
            Me.button1.Name = "button1"
            Me.button1.Size = New System.Drawing.Size(105, 23)
            Me.button1.TabIndex = 6
            Me.button1.Text = "Collapse all items"
            Me.button1.UseVisualStyleBackColor = True
            AddHandler Me.button1.Click, AddressOf button1_Click
            ' 
            ' label1
            ' 
            Me.label1.AutoSize = True
            Me.label1.Location = New System.Drawing.Point(207, 17)
            Me.label1.Name = "label1"
            Me.label1.Size = New System.Drawing.Size(62, 13)
            Me.label1.TabIndex = 5
            Me.label1.Text = "Commands:"
            ' 
            ' button2
            ' 
            Me.button2.Location = New System.Drawing.Point(207, 73)
            Me.button2.Name = "button2"
            Me.button2.Size = New System.Drawing.Size(105, 23)
            Me.button2.TabIndex = 7
            Me.button2.Text = "Disable all items"
            Me.button2.UseVisualStyleBackColor = True
            AddHandler Me.button2.Click, AddressOf button2_Click
            ' 
            ' listBox1
            ' 
            Me.listBox1.FormattingEnabled = True
            Me.listBox1.Location = New System.Drawing.Point(10, 143)
            Me.listBox1.Name = "listBox1"
            Me.listBox1.Size = New System.Drawing.Size(182, 82)
            Me.listBox1.TabIndex = 1
            ' 
            ' gcRadioGroupBox1
            ' 
            Me.gcRadioGroupBox1.Location = New System.Drawing.Point(10, 36)
            Me.gcRadioGroupBox1.Name = "gcRadioGroupBox1"
            Me.gcRadioGroupBox1.Size = New System.Drawing.Size(155, 101)
            Me.gcRadioGroupBox1.TabIndex = 0
            ' 
            ' checkBox1
            ' 
            Me.checkBox1.AutoSize = True
            Me.checkBox1.Location = New System.Drawing.Point(13, 13)
            Me.checkBox1.Name = "checkBox1"
            Me.checkBox1.Size = New System.Drawing.Size(118, 17)
            Me.checkBox1.TabIndex = 8
            Me.checkBox1.Text = "Button Appearance"
            Me.checkBox1.UseVisualStyleBackColor = True
            AddHandler Me.checkBox1.CheckedChanged, AddressOf checkBox1_CheckedChanged
            ' 
            ' GcRadioGroupBoxForm
            ' 
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0F, 13.0F)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(339, 241)
            Me.Controls.Add(Me.checkBox1)
            Me.Controls.Add(Me.listBox1)
            Me.Controls.Add(Me.gcRadioGroupBox1)
            Me.Controls.Add(Me.button2)
            Me.Controls.Add(Me.label1)
            Me.Controls.Add(Me.button1)
            Me.Name = "GcRadioGroupBoxForm"
            Me.Text = "GcRadioGroupBox"
            DirectCast((Me.gcRadioGroupBox1), System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
            Me.PerformLayout()

        End Sub

        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing AndAlso (components IsNot Nothing) Then
                components.Dispose()
            End If
            MyBase.Dispose(disposing)
        End Sub

        Public Sub New()
            InitializeComponent()

            InitializeGcRadioGroupBox()

            Me.DisplayAllItems()
        End Sub

        Private Sub InitializeGcRadioGroupBox()
            ' Set header text by setting the Text property.
            Me.gcRadioGroupBox1.Text = "&Collapse All"

            ' Enable gcRadioGroupBox1 to expand or collapse. 
            Me.gcRadioGroupBox1.HeaderType = HeaderType.ExpanderAndText

            ' Create a top-line border radio group box.
            Me.gcRadioGroupBox1.GroupStyle = GroupStyle.TopLine

            ' Initialize the layout of items by LayoutSettings.
            Me.gcRadioGroupBox1.LayoutSettings.LayoutMode = LayoutMode.Table
            Me.gcRadioGroupBox1.LayoutSettings.Orientation = System.Windows.Forms.Orientation.Vertical
            Me.gcRadioGroupBox1.LayoutSettings.RowCount = 3
            Me.gcRadioGroupBox1.LayoutSettings.HorizontalAdjustment = LineAdjustment.Distributed
            Me.gcRadioGroupBox1.LayoutSettings.VerticalAdjustment = LineAdjustment.Average

            AddHandler Me.gcRadioGroupBox1.CheckedItemChanged, AddressOf gcRadioGroupBox1_CheckedItemChanged
            AddHandler Me.gcRadioGroupBox1.HeaderStateChange, AddressOf gcRadioGroupBox1_HeaderStateChange

            ' Create and add some items.
            Dim items As RadioButtonItem() = New RadioButtonItem() {New RadioButtonItem("item1"), New RadioButtonItem("item2"), New RadioButtonItem("item3"), New RadioButtonItem("item4"), New RadioButtonItem("item5")}
            Me.gcRadioGroupBox1.Items.AddRange(items)
        End Sub

        ' Fill listBox1 with all the items in gcRadioGroupBox1.
        Private Sub DisplayAllItems()
            ' Display all the items of gcRadioGroupBox1 in list box.
            Me.listBox1.Items.Clear()
            Dim items As RadioButtonItemCollection = Me.gcRadioGroupBox1.Items
            For Each item As RadioButtonItem In items
                Dim index As Integer = Me.listBox1.Items.Add(item.Text + " index: " + items.IndexOf(item).ToString() + " checked state: " + item.Checked.ToString())
            Next

            ' Select the corresponding item in listBox1.
            Me.listBox1.SelectedIndex = Me.gcRadioGroupBox1.CheckedIndex
        End Sub

        ' Click button1 will expand or collapse gcRadioGroupBox1.
        Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
            If Me.gcRadioGroupBox1.IsExpanded Then
                Me.gcRadioGroupBox1.Collapse()
            Else
                Me.gcRadioGroupBox1.Expand()
            End If
            Me.UpdateButton1Text()
        End Sub

        ' Click button2 will enable or disable all items.
        Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)
            If AreAllItemsDisabled Then
                Me.gcRadioGroupBox1.EnableAllItems()
            Else
                Me.gcRadioGroupBox1.DisableAllItems()
            End If

            ' Update button3's text to appropriate value.
            Me.UpdateButton2Text()
        End Sub

        ' Update the items for listBox1 when item checked changed in gcRadioGroupBox1,
        Private Sub gcRadioGroupBox1_CheckedItemChanged(ByVal sender As Object, ByVal e As CheckedItemChangedEventArgs)
            If e.CurrentCheckedItem IsNot Nothing Then
                ' Use special styles for checked items.
                e.CurrentCheckedItem.ForeColor = Color.Red
                e.CurrentCheckedItem.Font = New Font(e.CurrentCheckedItem.Font, FontStyle.Bold)
            End If

            If e.OriginalCheckedItem IsNot Nothing Then
                ' Reset these properties will cause the properties to retreive their values from gcRadioGroupBox1.
                e.OriginalCheckedItem.ForeColor = Color.Empty
                e.OriginalCheckedItem.Font = Nothing
            End If

            ' Update the items displayed in listBox1.
            Me.DisplayAllItems()
        End Sub

        ' update the header text when gcRadioGroupBox1's header state is changed.
        Private Sub gcRadioGroupBox1_HeaderStateChange(ByVal sender As Object, ByVal e As HeaderStateChangeEventArgs)
            Me.UpdateHeaderText()
            Me.UpdateButton1Text()
        End Sub

        ' Update the header text according to the current header type and header state.
        Private Sub UpdateHeaderText()
            If Me.gcRadioGroupBox1.HeaderType = HeaderType.ExpanderAndText Then
                If Me.gcRadioGroupBox1.HeaderState = HeaderState.Expanded Then
                    Me.gcRadioGroupBox1.Text = "&Collapse All"
                Else
                    Me.gcRadioGroupBox1.Text = "&Expand All"
                End If
            End If
        End Sub

        ' Change the appearance of all items in gcRadioGroupBox1.
        Private Sub checkBox1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
            If Me.checkBox1.Checked Then
                Me.gcRadioGroupBox1.ItemSettings.Appearance = Appearance.Button
            Else
                Me.gcRadioGroupBox1.ItemSettings.Appearance = Appearance.Normal
            End If
        End Sub

        ' Update the button1's text according to whether gcRadioGroupBox1 is expanded.
        Private Sub UpdateButton1Text()
            If Me.gcRadioGroupBox1.IsExpanded Then
                Me.button1.Text = "Collapse all items"
            Else
                Me.button1.Text = "Expand all items"
            End If
        End Sub

        ' Update the button1's text according to whether all items in gcRadioGroupBox1 are enabled.
        Private Sub UpdateButton2Text()
            If AreAllItemsDisabled Then
                Me.button2.Text = "Enable all items"
            Else
                Me.button2.Text = "Disable all items"
            End If
        End Sub

        Private ReadOnly Property AreAllItemsDisabled() As Boolean
            Get
                For Each item As RadioButtonItem In Me.gcRadioGroupBox1.Items
                    If item.Enabled Then
                        Return False
                    End If
                Next
                Return True
            End Get
        End Property

    End Class

End Namespace
継承階層

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.Control
            GrapeCity.Framework.Forms.FrameworkControl
               GrapeCity.Framework.Views.Windows.ElementContainerControl
                  GrapeCity.Framework.Forms.ControlBase
                     GrapeCity.Win.Common.PlusPakControlBase
                        GrapeCity.Win.Containers.GcGroupBoxControlBase
                           GrapeCity.Win.Containers.GcRadioGroupBox

プラットフォーム

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

参照

GcRadioGroupBox メンバ
GrapeCity.Win.Containers 名前空間
GcGroupBoxControlBase クラス
GcCheckedGroupBox クラス
GcGroupBoxControlBase クラス
GcCheckedGroupBox クラス
GcGroupBoxControlBase クラス
GcCheckedGroupBox クラス

Send Feedback