C++ > CLI:テーブルレイアウトパネル

基本プロジェクトにテーブルレイアウトパネルを配置します。


プロパティの Dock を Fill にします。


テーブルレイアウトパネル上で右クリックして列を追加します。


せっかくなので行も追加します。


それぞれのレイアウト区画をだいたい同じ大きさになるように
調整します。


レイアウト区画に適当にコントロールを配置してみます。


このように行と列に区画を分けてコントロールを配置できるのが
テーブルレイアウトパネルです。
ビルドして実行してみましょう。

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::TableLayoutPanel^  tableLayoutPanel1;
 protected:
 private: System::Windows::Forms::Button^  button1;
 private: System::Windows::Forms::TabControl^  tabControl1;
 private: System::Windows::Forms::TabPage^  tabPage1;
 private: System::Windows::Forms::TabPage^  tabPage2;
 private: System::Windows::Forms::TrackBar^  trackBar1;
 private: System::Windows::Forms::TextBox^  textBox1;
 private: System::Windows::Forms::RadioButton^  radioButton1;
 private: System::Windows::Forms::DomainUpDown^  domainUpDown1;


 protected:

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

#pragma region Windows Form Designer generated code
  /// <summary>
  /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
  /// コード エディターで変更しないでください。
  /// </summary>
  void InitializeComponent(void)
  {
   this->tableLayoutPanel1 = (gcnew System::Windows::Forms::TableLayoutPanel());
   this->button1 = (gcnew System::Windows::Forms::Button());
   this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
   this->tabPage1 = (gcnew System::Windows::Forms::TabPage());
   this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
   this->trackBar1 = (gcnew System::Windows::Forms::TrackBar());
   this->textBox1 = (gcnew System::Windows::Forms::TextBox());
   this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
   this->domainUpDown1 = (gcnew System::Windows::Forms::DomainUpDown());
   this->tableLayoutPanel1->SuspendLayout();
   this->tabControl1->SuspendLayout();
   (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->trackBar1))->BeginInit();
   this->SuspendLayout();
   //
   // tableLayoutPanel1
   //
   this->tableLayoutPanel1->ColumnCount = 3;
   this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent,
    49.21466F)));
   this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent,
    50.78534F)));
   this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Absolute,
    92)));
   this->tableLayoutPanel1->Controls->Add(this->button1, 1, 0);
   this->tableLayoutPanel1->Controls->Add(this->tabControl1, 0, 2);
   this->tableLayoutPanel1->Controls->Add(this->trackBar1, 2, 1);
   this->tableLayoutPanel1->Controls->Add(this->textBox1, 2, 2);
   this->tableLayoutPanel1->Controls->Add(this->radioButton1, 2, 0);
   this->tableLayoutPanel1->Controls->Add(this->domainUpDown1, 1, 1);
   this->tableLayoutPanel1->Dock = System::Windows::Forms::DockStyle::Fill;
   this->tableLayoutPanel1->Location = System::Drawing::Point(0, 0);
   this->tableLayoutPanel1->Name = L"tableLayoutPanel1";
   this->tableLayoutPanel1->RowCount = 3;
   this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 50)));
   this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 50)));
   this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Absolute, 85)));
   this->tableLayoutPanel1->Size = System::Drawing::Size(284, 261);
   this->tableLayoutPanel1->TabIndex = 0;
   //
   // button1
   //
   this->button1->Location = System::Drawing::Point(97, 3);
   this->button1->Name = L"button1";
   this->button1->Size = System::Drawing::Size(91, 82);
   this->button1->TabIndex = 0;
   this->button1->Text = L"button1";
   this->button1->UseVisualStyleBackColor = true;
   //
   // tabControl1
   //
   this->tabControl1->Controls->Add(this->tabPage1);
   this->tabControl1->Controls->Add(this->tabPage2);
   this->tabControl1->Location = System::Drawing::Point(3, 179);
   this->tabControl1->Name = L"tabControl1";
   this->tabControl1->SelectedIndex = 0;
   this->tabControl1->Size = System::Drawing::Size(88, 79);
   this->tabControl1->TabIndex = 1;
   //
   // tabPage1
   //
   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(80, 53);
   this->tabPage1->TabIndex = 0;
   this->tabPage1->Text = L"tabPage1";
   this->tabPage1->UseVisualStyleBackColor = true;
   //
   // tabPage2
   //
   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(80, 53);
   this->tabPage2->TabIndex = 1;
   this->tabPage2->Text = L"tabPage2";
   this->tabPage2->UseVisualStyleBackColor = true;
   //
   // trackBar1
   //
   this->trackBar1->Location = System::Drawing::Point(194, 91);
   this->trackBar1->Name = L"trackBar1";
   this->trackBar1->Size = System::Drawing::Size(87, 45);
   this->trackBar1->TabIndex = 2;
   //
   // textBox1
   //
   this->textBox1->Dock = System::Windows::Forms::DockStyle::Fill;
   this->textBox1->Location = System::Drawing::Point(194, 179);
   this->textBox1->Multiline = true;
   this->textBox1->Name = L"textBox1";
   this->textBox1->Size = System::Drawing::Size(87, 79);
   this->textBox1->TabIndex = 3;
   //
   // radioButton1
   //
   this->radioButton1->AutoSize = true;
   this->radioButton1->Location = System::Drawing::Point(194, 3);
   this->radioButton1->Name = L"radioButton1";
   this->radioButton1->Size = System::Drawing::Size(87, 16);
   this->radioButton1->TabIndex = 4;
   this->radioButton1->TabStop = true;
   this->radioButton1->Text = L"radioButton1";
   this->radioButton1->UseVisualStyleBackColor = true;
   //
   // domainUpDown1
   //
   this->domainUpDown1->Location = System::Drawing::Point(97, 91);
   this->domainUpDown1->Name = L"domainUpDown1";
   this->domainUpDown1->Size = System::Drawing::Size(91, 19);
   this->domainUpDown1->TabIndex = 5;
   this->domainUpDown1->Text = L"domainUpDown1";
   //
   // 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->tableLayoutPanel1);
   this->Name = L"MyForm";
   this->Text = L"Hello C++/CLI World !!";
   this->tableLayoutPanel1->ResumeLayout(false);
   this->tableLayoutPanel1->PerformLayout();
   this->tabControl1->ResumeLayout(false);
   (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->trackBar1))->EndInit();
   this->ResumeLayout(false);

  }
#pragma endregion

 };
}

 

 

 

 

 

 

最終更新:2013年10月06日 20:04