C++ > CLI:タブコントロール

基本プロジェクトにタブコントロールを配置します。


タブページ1にボタンを配置します。


タブページ2にチェックボックスを配置します。


ビルドして実行してみましょう。

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::TabControl^  tabControl1;
 protected:
 private: System::Windows::Forms::TabPage^  tabPage1;
 private: System::Windows::Forms::Button^  button1;
 private: System::Windows::Forms::TabPage^  tabPage2;
 private: System::Windows::Forms::CheckBox^  checkBox1;


 protected:

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

#pragma region Windows Form Designer generated code
  /// <summary>
  /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
  /// コード エディターで変更しないでください。
  /// </summary>
  void InitializeComponent(void)
  {
   this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
   this->tabPage1 = (gcnew System::Windows::Forms::TabPage());
   this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
   this->button1 = (gcnew System::Windows::Forms::Button());
   this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
   this->tabControl1->SuspendLayout();
   this->tabPage1->SuspendLayout();
   this->tabPage2->SuspendLayout();
   this->SuspendLayout();
   //
   // tabControl1
   //
   this->tabControl1->Controls->Add(this->tabPage1);
   this->tabControl1->Controls->Add(this->tabPage2);
   this->tabControl1->Location = System::Drawing::Point(29, 54);
   this->tabControl1->Name = L"tabControl1";
   this->tabControl1->SelectedIndex = 0;
   this->tabControl1->Size = System::Drawing::Size(200, 100);
   this->tabControl1->TabIndex = 0;
   //
   // tabPage1
   //
   this->tabPage1->Controls->Add(this->button1);
   this->tabPage1->Location = System::Drawing::Point(4, 22);
   this->tabPage1->Name = L"tabPage1";
   this->tabPage1->Padding = System::Windows::Forms::Padding(3);
   this->tabPage1->Size = System::Drawing::Size(192, 74);
   this->tabPage1->TabIndex = 0;
   this->tabPage1->Text = L"tabPage1";
   this->tabPage1->UseVisualStyleBackColor = true;
   //
   // tabPage2
   //
   this->tabPage2->Controls->Add(this->checkBox1);
   this->tabPage2->Location = System::Drawing::Point(4, 22);
   this->tabPage2->Name = L"tabPage2";
   this->tabPage2->Padding = System::Windows::Forms::Padding(3);
   this->tabPage2->Size = System::Drawing::Size(192, 74);
   this->tabPage2->TabIndex = 1;
   this->tabPage2->Text = L"tabPage2";
   this->tabPage2->UseVisualStyleBackColor = true;
   //
   // button1
   //
   this->button1->Location = System::Drawing::Point(38, 27);
   this->button1->Name = L"button1";
   this->button1->Size = System::Drawing::Size(75, 23);
   this->button1->TabIndex = 0;
   this->button1->Text = L"button1";
   this->button1->UseVisualStyleBackColor = true;
   //
   // checkBox1
   //
   this->checkBox1->AutoSize = true;
   this->checkBox1->Location = System::Drawing::Point(39, 26);
   this->checkBox1->Name = L"checkBox1";
   this->checkBox1->Size = System::Drawing::Size(80, 16);
   this->checkBox1->TabIndex = 0;
   this->checkBox1->Text = L"checkBox1";
   this->checkBox1->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->tabControl1);
   this->Name = L"MyForm";
   this->Text = L"Hello C++/CLI World !!";
   this->tabControl1->ResumeLayout(false);
   this->tabPage1->ResumeLayout(false);
   this->tabPage2->ResumeLayout(false);
   this->tabPage2->PerformLayout();
   this->ResumeLayout(false);

  }
#pragma endregion

 };
}

 

 

 

 

 

 

最終更新:2013年09月23日 14:20