C++ > CLI:グループボックス

基本プロジェクトにグループボックスを2つ配置します。


それぞれのグループボックス上にラジオボタンを2つずつ、
配置します。


ビルドして実行してみましょう。
通常はラジオボタンは1つしか選択できないはずですが、
グループボックスで分けることによって、ラジオボタンの1と2、
3と4が別々のグループとして扱われ、それぞれのグループごとに
選択できるようになります。

MyForm.cpp

#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
#include "MyForm.h"

using namespace Project1;

[STAThreadAttribute]
int main(){
 MyForm ^form1 = gcnew MyForm;
 form1->ShowDialog();
 return 0;
}

MyForm.h

#pragma once

namespace Project1 {

 using namespace System;
 using namespace System::ComponentModel;
 using namespace System::Collections;
 using namespace System::Windows::Forms;
 using namespace System::Data;
 using namespace System::Drawing;

 /// <summary>
 /// MyForm の概要
 /// </summary>
 public ref class MyForm : public System::Windows::Forms::Form
 {
 public:
  MyForm(void)
  {
   InitializeComponent();
   //
   //TODO: ここにコンストラクター コードを追加します
   //
  }

 protected:
  /// <summary>
  /// 使用中のリソースをすべてクリーンアップします。
  /// </summary>
  ~MyForm()
  {
   if (components)
   {
    delete components;
   }
  }
 private: System::Windows::Forms::GroupBox^  groupBox1;
 protected:
 private: System::Windows::Forms::RadioButton^  radioButton2;
 private: System::Windows::Forms::RadioButton^  radioButton1;
 private: System::Windows::Forms::GroupBox^  groupBox2;
 private: System::Windows::Forms::RadioButton^  radioButton4;
 private: System::Windows::Forms::RadioButton^  radioButton3;


 protected:

 private:
  /// <summary>
  /// 必要なデザイナー変数です。
  /// </summary>
  System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
  /// <summary>
  /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
  /// コード エディターで変更しないでください。
  /// </summary>
  void InitializeComponent(void)
  {
   this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
   this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
   this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
   this->radioButton2 = (gcnew System::Windows::Forms::RadioButton());
   this->radioButton3 = (gcnew System::Windows::Forms::RadioButton());
   this->radioButton4 = (gcnew System::Windows::Forms::RadioButton());
   this->groupBox1->SuspendLayout();
   this->groupBox2->SuspendLayout();
   this->SuspendLayout();
   //
   // groupBox1
   //
   this->groupBox1->Controls->Add(this->radioButton2);
   this->groupBox1->Controls->Add(this->radioButton1);
   this->groupBox1->Location = System::Drawing::Point(12, 12);
   this->groupBox1->Name = L"groupBox1";
   this->groupBox1->Size = System::Drawing::Size(200, 100);
   this->groupBox1->TabIndex = 0;
   this->groupBox1->TabStop = false;
   this->groupBox1->Text = L"groupBox1";
   //
   // groupBox2
   //
   this->groupBox2->Controls->Add(this->radioButton4);
   this->groupBox2->Controls->Add(this->radioButton3);
   this->groupBox2->Location = System::Drawing::Point(12, 149);
   this->groupBox2->Name = L"groupBox2";
   this->groupBox2->Size = System::Drawing::Size(200, 100);
   this->groupBox2->TabIndex = 1;
   this->groupBox2->TabStop = false;
   this->groupBox2->Text = L"groupBox2";
   //
   // radioButton1
   //
   this->radioButton1->AutoSize = true;
   this->radioButton1->Location = System::Drawing::Point(21, 31);
   this->radioButton1->Name = L"radioButton1";
   this->radioButton1->Size = System::Drawing::Size(88, 16);
   this->radioButton1->TabIndex = 0;
   this->radioButton1->TabStop = true;
   this->radioButton1->Text = L"radioButton1";
   this->radioButton1->UseVisualStyleBackColor = true;
   //
   // radioButton2
   //
   this->radioButton2->AutoSize = true;
   this->radioButton2->Location = System::Drawing::Point(21, 63);
   this->radioButton2->Name = L"radioButton2";
   this->radioButton2->Size = System::Drawing::Size(88, 16);
   this->radioButton2->TabIndex = 1;
   this->radioButton2->TabStop = true;
   this->radioButton2->Text = L"radioButton2";
   this->radioButton2->UseVisualStyleBackColor = true;
   //
   // radioButton3
   //
   this->radioButton3->AutoSize = true;
   this->radioButton3->Location = System::Drawing::Point(21, 34);
   this->radioButton3->Name = L"radioButton3";
   this->radioButton3->Size = System::Drawing::Size(88, 16);
   this->radioButton3->TabIndex = 0;
   this->radioButton3->TabStop = true;
   this->radioButton3->Text = L"radioButton3";
   this->radioButton3->UseVisualStyleBackColor = true;
   //
   // radioButton4
   //
   this->radioButton4->AutoSize = true;
   this->radioButton4->Location = System::Drawing::Point(21, 66);
   this->radioButton4->Name = L"radioButton4";
   this->radioButton4->Size = System::Drawing::Size(88, 16);
   this->radioButton4->TabIndex = 1;
   this->radioButton4->TabStop = true;
   this->radioButton4->Text = L"radioButton4";
   this->radioButton4->UseVisualStyleBackColor = true;
   //
   // MyForm
   //
   this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
   this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
   this->ClientSize = System::Drawing::Size(284, 261);
   this->Controls->Add(this->groupBox2);
   this->Controls->Add(this->groupBox1);
   this->Name = L"MyForm";
   this->Text = L"Hello C++/CLI World !!";
   this->groupBox1->ResumeLayout(false);
   this->groupBox1->PerformLayout();
   this->groupBox2->ResumeLayout(false);
   this->groupBox2->PerformLayout();
   this->ResumeLayout(false);

  }
#pragma endregion

 };
}

 

 

 

 

 

 

最終更新:2013年09月23日 14:08
添付ファイル