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

チェックボックス項目のグループを表示するWindowsコントロールを表します。
構文
Public Class GcCheckedGroupBox 
   Inherits GcGroupBoxControlBase
public class GcCheckedGroupBox : GcGroupBoxControlBase 
解説

このクラスはGcGroupBoxControlBaseクラスから継承され、子CheckBoxItemに関連する特有の機能を実装します。このコントロールは、CheckBoxItemCollectionコレクションに含まれる一連の項目を表示します。ユーザーはキーボードを使用してこれらの項目を移動し、1つ以上の項目にチェックマークを付けることができます。チェックマークの付いた項目は、CheckedCheckBoxItemCollectionCheckedCheckBoxIndexCollectionを使用して確認できます。

また、CheckAllItemsメソッドまたはUncheckAllItemsメソッドを使用するとすべての項目のチェックボックスをオン/オフでき、EnableAllItemsメソッドまたはDisableAllItemsメソッドを使用するとすべての項目を有効または無効にできます。

GcCheckedGroupBoxクラスは次の3つのインデックス付きコレクションをサポートしています。

コレクション カプセル化クラス
GcCheckedGroupBoxコントロール内のすべての項目を含むItems。ユーザーはこのコレクションを使用して、GcCheckedGroupBox内の項目を追加、削除し、項目数を取得できます。 CheckBoxItemCollection
GcCheckedGroupBoxコントロールに含まれる項目のサブセットであるCheckedItems。これには、GcCheckedGroupBoxコントロール内のオンになっている項目がすべて含まれます。 CheckedCheckBoxItemCollection
ItemsコレクションへのインデックスのサブセットであるCheckedIndices。これらのインデックスは、オンになっている項目を指定します。 CheckedCheckBoxIndexCollection

以下の3つの表に、GcCheckedGroupBoxクラスでサポートされている3つのインデックス付きコレクションの例を示します。

最初の表は、コントロール内の項目(コントロールに含まれるすべての項目)のインデックス付きコレクションの例を示します。

インデックス 項目 チェック状態
0 項目1 false
1 項目2 true
2 項目3 false
3 項目4 true
4 項目5 true

2番目の表は、オンになっている項目を含むインデックス付きコレクションの例を示します。

インデックス 項目
0 項目2
1 項目4
2 項目5

3番目の表は、オンになっている項目のインデックスを含むインデックス付きコレクションの例を示します。

インデックス 項目
0 1
1 3
2 4

プログラムまたはUI操作によってCheckBoxItem.Checkedプロパティが変更されると、ItemCheckedChangedイベントが発生します。項目の境界の中でマウス左ボタンをクリックすると、ItemClickイベントが発生します。

使用例
次のサンプルコードは、GcCheckedGroupBoxコントロールのメソッド、プロパティ、およびコレクションの使用方法を示します。これはプロジェクトにコピー&ペーストするだけですぐに実行できる完成したサンプルです。
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;

namespace GrapeCity.Win.PlusPak.SampleCodes_CS
{
    public class GcCheckedGroupBoxForm : Form
    {
        private GrapeCity.Win.Containers.GcCheckedGroupBox gcCheckedGroupBox1;
        private System.Windows.Forms.ListBox listBox1;
        private Button button1;
        private ComboBox comboBox1;
        private Label label1;
        private Button button2;
        private Button button3;
        private CheckBox checkBox1;
        private System.ComponentModel.IContainer components = null;

        private void InitializeComponent()
        {
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.button1 = new System.Windows.Forms.Button();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.label1 = new System.Windows.Forms.Label();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.checkBox1 = new System.Windows.Forms.CheckBox();
            this.gcCheckedGroupBox1 = new GrapeCity.Win.Containers.GcCheckedGroupBox();
            ((System.ComponentModel.ISupportInitialize)(this.gcCheckedGroupBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // listBox1
            // 
            this.listBox1.FormattingEnabled = true;
            this.listBox1.Location = new System.Drawing.Point(12, 158);
            this.listBox1.Name = "listBox1";
            this.listBox1.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
            this.listBox1.Size = new System.Drawing.Size(202, 108);
            this.listBox1.TabIndex = 1;
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(236, 40);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(112, 23);
            this.button1.TabIndex = 11;
            this.button1.Text = "Collapse all items";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // comboBox1
            // 
            this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Items.AddRange(new object[] {
            "All items",
            "Checked items",
            "Checked indices"});
            this.comboBox1.Location = new System.Drawing.Point(12, 131);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(103, 21);
            this.comboBox1.TabIndex = 12;
            this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.ComboBox_SelectedIndexChanged);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(236, 13);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(62, 13);
            this.label1.TabIndex = 13;
            this.label1.Text = "Commands:";
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(236, 68);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(112, 23);
            this.button2.TabIndex = 14;
            this.button2.Text = "Uncheck all items";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(236, 97);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(109, 23);
            this.button3.TabIndex = 15;
            this.button3.Text = "Disable all items";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // checkBox1
            // 
            this.checkBox1.AutoSize = true;
            this.checkBox1.Location = new System.Drawing.Point(12, 9);
            this.checkBox1.Name = "checkBox1";
            this.checkBox1.Size = new System.Drawing.Size(118, 17);
            this.checkBox1.TabIndex = 16;
            this.checkBox1.Text = "Button Appearance";
            this.checkBox1.UseVisualStyleBackColor = true;
            this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
            // 
            // gcCheckedGroupBox1
            // 
            this.gcCheckedGroupBox1.Location = new System.Drawing.Point(12, 32);
            this.gcCheckedGroupBox1.Name = "gcCheckedGroupBox1";
            this.gcCheckedGroupBox1.Size = new System.Drawing.Size(150, 93);
            this.gcCheckedGroupBox1.TabIndex = 0;
            // 
            // GcCheckedGroupBoxForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(407, 275);
            this.Controls.Add(this.checkBox1);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.comboBox1);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.listBox1);
            this.Controls.Add(this.gcCheckedGroupBox1);
            this.Name = "GcCheckedGroupBoxForm";
            this.Text = "GcCheckedGroupBox";
            ((System.ComponentModel.ISupportInitialize)(this.gcCheckedGroupBox1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

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

        public GcCheckedGroupBoxForm()
        {
            InitializeComponent();

            InitializeMyGcCheckedGroupBox();

            this.comboBox1.SelectedIndex = 0;
        }

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

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

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

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

            this.gcCheckedGroupBox1.ItemCheckedChanged +=
                new System.EventHandler<GrapeCity.Win.Containers.CheckBoxItemEventArgs>(this.gcCheckedGroupBox1_ItemCheckedChanged);
            this.gcCheckedGroupBox1.HeaderStateChange +=
                new System.EventHandler<GrapeCity.Win.Containers.HeaderStateChangeEventArgs>(this.gcCheckedGroupBox1_HeaderStateChange);

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

        // Update the items for listBox1 when item checked changed in gcCheckedGroupBox1,
        private void gcCheckedGroupBox1_ItemCheckedChanged(object sender, GrapeCity.Win.Containers.CheckBoxItemEventArgs e)
        {
            if (e.CheckBoxItem.Checked)
            {
                // Set special styles for checked items.
                e.CheckBoxItem.ForeColor = Color.Red;
                e.CheckBoxItem.Font = new Font(e.CheckBoxItem.Font, FontStyle.Bold);
            }
            else
            {
                // Reset these properties will cause the properties to retrieve their values from gcCheckedGroupBox1.
                e.CheckBoxItem.ForeColor = Color.Empty;
                e.CheckBoxItem.Font = null;
            }

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

        // Display different type of items according to the current comboBox1's SelectedIndex.
        private void DisplayItems()
        {
            if (this.comboBox1.SelectedIndex == 0)
            {
                this.DisplayAllItems();
            }
            else if (this.comboBox1.SelectedIndex == 1)
            {
                this.DisplayAllCheckedItems();
            }
            else if (this.comboBox1.SelectedIndex == 2)
            {
                this.DisplayAllCheckedIndices();
            }
        }

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

        // Fill listBox1 with all the checked items in gcCheckedGroupBox1.
        private void DisplayAllCheckedItems()
        {
            // Display all checked items of gcCheckedGroupBox1 in list box.
            this.listBox1.Items.Clear();
            CheckedCheckBoxItemCollection checkedItems = this.gcCheckedGroupBox1.CheckedItems;
            foreach (CheckBoxItem item in checkedItems)
            {
                this.listBox1.Items.Add(item.Text);
            }
        }

        // Fill listBox1 with all the indices of checked items in gcCheckedGroupBox1.
        private void DisplayAllCheckedIndices()
        {
            // Display all the indices of checked items of gcCheckedGroupBox1 in list box.
            this.listBox1.Items.Clear();
            CheckedCheckBoxIndexCollection checkedIndices = this.gcCheckedGroupBox1.CheckedIndices;
            foreach (int index in checkedIndices)
            {
                this.listBox1.Items.Add(index.ToString());
            }
        }

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

        // Click the button2 will check or uncheck all the check box items.
        private void button2_Click(object sender, EventArgs e)
        {
            if (AreAllItemsUnchecked)
            {
                this.gcCheckedGroupBox1.CheckAllItems();
            }
            else
            {
                this.gcCheckedGroupBox1.UncheckAllItems();
            }

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

        // Click button3 will enable or disable all the check box items.
        private void button3_Click(object sender, EventArgs e)
        {
            if (AreAllItemsDisabled)
            {
                this.gcCheckedGroupBox1.EnableAllItems();
            }
            else
            {
                this.gcCheckedGroupBox1.DisableAllItems();
            }

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

        // update the header text when gcCheckedGroupBox1's header state changes.
        private void gcCheckedGroupBox1_HeaderStateChange(object sender, HeaderStateChangeEventArgs e)
        {
            if (e.CurrentState == HeaderState.Expanded)
            {
                this.gcCheckedGroupBox1.Text = "&Collapse All";
            }
            else if (e.CurrentState == HeaderState.Collapsed)
            {
                this.gcCheckedGroupBox1.Text = "&Expand All";
            }

            this.UpdateButton1Text();
        }

        // Display the items in listBox1 when comboBox1 selected index is changed.
        private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DisplayItems();
        }

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

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

        // Update the button2's text according to whether all the items in gcCheckedGroupBox1 are checked.
        private void UpdateButton2Text()
        {
            if (AreAllItemsUnchecked)
            {
                this.button2.Text = "Check all items";

            }
            else
            {
                this.button2.Text = "Uncheck all items";
            }
        }

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

        private bool AreAllItemsUnchecked
        {
            get
            {
                if (this.gcCheckedGroupBox1.HeaderType == HeaderType.CheckerAndText)
                {
                    return this.gcCheckedGroupBox1.HeaderState == HeaderState.Unchecked;
                }
                else
                {
                    return this.gcCheckedGroupBox1.CheckedItems.Count == 0;
                }
            }
        }
        private bool AreAllItemsDisabled
        {
            get
            {
                if (this.gcCheckedGroupBox1.HeaderType == HeaderType.EnablerAndText)
                {
                    return this.gcCheckedGroupBox1.HeaderState == HeaderState.Unchecked;
                }
                else
                {
                    foreach (CheckBoxItem item in this.gcCheckedGroupBox1.Items)
                    {
                        if (item.Enabled)
                            return false;
                    }
                    return true;
                }
            }
        }

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

}
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

Namespace GrapeCity.Win.PlusPak.SampleCodes_VB
    Public Class GcCheckedGroupBoxForm
        Inherits Form
        Private gcCheckedGroupBox1 As GcCheckedGroupBox
        Private listBox1 As System.Windows.Forms.ListBox
        Private button1 As Button
        Private comboBox1 As ComboBox
        Private label1 As Label
        Private button2 As Button
        Private button3 As Button
        Private checkBox1 As CheckBox
        Private components As System.ComponentModel.IContainer = Nothing

        Private Sub InitializeComponent()
            Me.listBox1 = New System.Windows.Forms.ListBox()
            Me.button1 = New System.Windows.Forms.Button()
            Me.comboBox1 = New System.Windows.Forms.ComboBox()
            Me.label1 = New System.Windows.Forms.Label()
            Me.button2 = New System.Windows.Forms.Button()
            Me.button3 = New System.Windows.Forms.Button()
            Me.checkBox1 = New System.Windows.Forms.CheckBox()
            Me.gcCheckedGroupBox1 = New GcCheckedGroupBox()
            DirectCast((Me.gcCheckedGroupBox1), System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            ' 
            ' listBox1
            ' 
            Me.listBox1.FormattingEnabled = True
            Me.listBox1.Location = New System.Drawing.Point(12, 158)
            Me.listBox1.Name = "listBox1"
            Me.listBox1.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended
            Me.listBox1.Size = New System.Drawing.Size(202, 108)
            Me.listBox1.TabIndex = 1
            ' 
            ' button1
            ' 
            Me.button1.Location = New System.Drawing.Point(236, 40)
            Me.button1.Name = "button1"
            Me.button1.Size = New System.Drawing.Size(112, 23)
            Me.button1.TabIndex = 11
            Me.button1.Text = "Collapse all items"
            Me.button1.UseVisualStyleBackColor = True
            AddHandler Me.button1.Click, AddressOf button1_Click
            ' 
            ' comboBox1
            ' 
            Me.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
            Me.comboBox1.FormattingEnabled = True
            Me.comboBox1.Items.AddRange(New Object() {"All items", "Checked items", "Checked indices"})
            Me.comboBox1.Location = New System.Drawing.Point(12, 131)
            Me.comboBox1.Name = "comboBox1"
            Me.comboBox1.Size = New System.Drawing.Size(103, 21)
            Me.comboBox1.TabIndex = 12
            AddHandler Me.comboBox1.SelectedIndexChanged, AddressOf Me.ComboBox_SelectedIndexChanged
            ' 
            ' label1
            ' 
            Me.label1.AutoSize = True
            Me.label1.Location = New System.Drawing.Point(236, 13)
            Me.label1.Name = "label1"
            Me.label1.Size = New System.Drawing.Size(62, 13)
            Me.label1.TabIndex = 13
            Me.label1.Text = "Commands:"
            ' 
            ' button2
            ' 
            Me.button2.Location = New System.Drawing.Point(236, 68)
            Me.button2.Name = "button2"
            Me.button2.Size = New System.Drawing.Size(112, 23)
            Me.button2.TabIndex = 14
            Me.button2.Text = "Uncheck all items"
            Me.button2.UseVisualStyleBackColor = True
            AddHandler Me.button2.Click, AddressOf Me.button2_Click
            ' 
            ' button3
            ' 
            Me.button3.Location = New System.Drawing.Point(236, 97)
            Me.button3.Name = "button3"
            Me.button3.Size = New System.Drawing.Size(109, 23)
            Me.button3.TabIndex = 15
            Me.button3.Text = "Disable all items"
            Me.button3.UseVisualStyleBackColor = True
            AddHandler Me.button3.Click, AddressOf Me.button3_Click
            ' 
            ' checkBox1
            ' 
            Me.checkBox1.AutoSize = True
            Me.checkBox1.Location = New System.Drawing.Point(12, 9)
            Me.checkBox1.Name = "checkBox1"
            Me.checkBox1.Size = New System.Drawing.Size(118, 17)
            Me.checkBox1.TabIndex = 16
            Me.checkBox1.Text = "Button Appearance"
            Me.checkBox1.UseVisualStyleBackColor = True
            AddHandler Me.checkBox1.CheckedChanged, AddressOf checkBox1_CheckedChanged
            ' 
            ' gcCheckedGroupBox1
            ' 
            Me.gcCheckedGroupBox1.Location = New System.Drawing.Point(12, 32)
            Me.gcCheckedGroupBox1.Name = "gcCheckedGroupBox1"
            Me.gcCheckedGroupBox1.Size = New System.Drawing.Size(150, 93)
            Me.gcCheckedGroupBox1.TabIndex = 0
            ' 
            ' GcCheckedGroupBoxForm
            ' 
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0F, 13.0F)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(407, 275)
            Me.Controls.Add(Me.checkBox1)
            Me.Controls.Add(Me.button3)
            Me.Controls.Add(Me.button2)
            Me.Controls.Add(Me.label1)
            Me.Controls.Add(Me.comboBox1)
            Me.Controls.Add(Me.button1)
            Me.Controls.Add(Me.listBox1)
            Me.Controls.Add(Me.gcCheckedGroupBox1)
            Me.Name = "GcCheckedGroupBoxForm"
            Me.Text = "GcCheckedGroupBox"
            DirectCast((Me.gcCheckedGroupBox1), 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()

            InitializeMyGcCheckedGroupBox()

            Me.comboBox1.SelectedIndex = 0
        End Sub

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

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

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

            ' Initialize the layout of items by LayoutSettings.
            Me.gcCheckedGroupBox1.LayoutSettings.LayoutMode = LayoutMode.Table
            Me.gcCheckedGroupBox1.LayoutSettings.Orientation = System.Windows.Forms.Orientation.Vertical
            Me.gcCheckedGroupBox1.LayoutSettings.RowCount = 3
            Me.gcCheckedGroupBox1.LayoutSettings.HorizontalAdjustment = LineAdjustment.Distributed
            Me.gcCheckedGroupBox1.LayoutSettings.VerticalAdjustment = LineAdjustment.Average
            AddHandler Me.gcCheckedGroupBox1.ItemCheckedChanged, AddressOf gcCheckedGroupBox1_ItemCheckedChanged
            AddHandler Me.gcCheckedGroupBox1.HeaderStateChange, AddressOf gcCheckedGroupBox1_HeaderStateChange

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

        ' Update the items for listBox1 when item checked changed in gcCheckedGroupBox1,
        Private Sub gcCheckedGroupBox1_ItemCheckedChanged(ByVal sender As Object, ByVal e As CheckBoxItemEventArgs)
            If e.CheckBoxItem.Checked Then
                ' Set special styles for checked items.
                e.CheckBoxItem.ForeColor = Color.Red
                e.CheckBoxItem.Font = New Font(e.CheckBoxItem.Font, FontStyle.Bold)
            Else
                ' Reset these properties will cause the properties to retrieve their values from gcCheckedGroupBox1.
                e.CheckBoxItem.ForeColor = Color.Empty
                e.CheckBoxItem.Font = Nothing
            End If

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

        ' Display different type of items according to the current comboBox1's SelectedIndex.
        Private Sub DisplayItems()
            If Me.comboBox1.SelectedIndex = 0 Then
                Me.DisplayAllItems()
            ElseIf Me.comboBox1.SelectedIndex = 1 Then
                Me.DisplayAllCheckedItems()
            ElseIf Me.comboBox1.SelectedIndex = 2 Then
                Me.DisplayAllCheckedIndices()
            End If
        End Sub

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

        ' Fill listBox1 with all the checked items in gcCheckedGroupBox1.
        Private Sub DisplayAllCheckedItems()
            ' Display all checked items of gcCheckedGroupBox1 in list box.
            Me.listBox1.Items.Clear()
            Dim checkedItems As CheckedCheckBoxItemCollection = Me.gcCheckedGroupBox1.CheckedItems
            For Each item As CheckBoxItem In checkedItems
                Me.listBox1.Items.Add(item.Text)
            Next
        End Sub

        ' Fill listBox1 with all the indices of checked items in gcCheckedGroupBox1.
        Private Sub DisplayAllCheckedIndices()
            ' Display all the indices of checked items of gcCheckedGroupBox1 in list box.
            Me.listBox1.Items.Clear()
            Dim checkedIndices As CheckedCheckBoxIndexCollection = Me.gcCheckedGroupBox1.CheckedIndices
            For Each index As Integer In checkedIndices
                Me.listBox1.Items.Add(index.ToString())
            Next
        End Sub

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

        ' Click the button2 will check or uncheck all the check box items.
        Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)
            If AreAllItemsUnchecked Then
                Me.gcCheckedGroupBox1.CheckAllItems()
            Else
                Me.gcCheckedGroupBox1.UncheckAllItems()
            End If

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

        ' Click button3 will enable or disable all the check box items.
        Private Sub button3_Click(ByVal sender As Object, ByVal e As EventArgs)
            If AreAllItemsDisabled Then
                Me.gcCheckedGroupBox1.EnableAllItems()
            Else
                Me.gcCheckedGroupBox1.DisableAllItems()
            End If

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

        ' update the header text when gcCheckedGroupBox1's header state changes.
        Private Sub gcCheckedGroupBox1_HeaderStateChange(ByVal sender As Object, ByVal e As HeaderStateChangeEventArgs)
            If e.CurrentState = HeaderState.Expanded Then
                Me.gcCheckedGroupBox1.Text = "&Collapse All"
            ElseIf e.CurrentState = HeaderState.Collapsed Then
                Me.gcCheckedGroupBox1.Text = "&Expand All"
            End If

            Me.UpdateButton1Text()
        End Sub

        ' Display the items in listBox1 when comboBox1 selected index is changed.
        Private Sub ComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
            Me.DisplayItems()
        End Sub

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

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

        ' Update the button2's text according to whether all the items in gcCheckedGroupBox1 are checked.
        Private Sub UpdateButton2Text()
            If AreAllItemsUnchecked Then

                Me.button2.Text = "Check all items"
            Else
                Me.button2.Text = "Uncheck all items"
            End If
        End Sub

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

        Private ReadOnly Property AreAllItemsUnchecked() As Boolean
            Get
                If Me.gcCheckedGroupBox1.HeaderType = HeaderType.CheckerAndText Then
                    Return Me.gcCheckedGroupBox1.HeaderState = HeaderState.Unchecked
                Else
                    Return Me.gcCheckedGroupBox1.CheckedItems.Count = 0
                End If
            End Get
        End Property
        Private ReadOnly Property AreAllItemsDisabled() As Boolean
            Get
                If Me.gcCheckedGroupBox1.HeaderType = HeaderType.EnablerAndText Then
                    Return Me.gcCheckedGroupBox1.HeaderState = HeaderState.Unchecked
                Else
                    For Each item As CheckBoxItem In Me.gcCheckedGroupBox1.Items
                        If item.Enabled Then
                            Return False
                        End If
                    Next
                    Return True
                End If
            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.GcCheckedGroupBox

プラットフォーム

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

参照

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

Send Feedback