C++ > CLI:フローレイアウトパネル

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


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


Button を適当に何個か、フローレイアウトパネル上に
配置してみましょう。


自動的にボタンが左上詰めで整列されます。
ビルドして実行してみましょう。

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::FlowLayoutPanel^  flowLayoutPanel1;
 protected:
 private: System::Windows::Forms::Button^  button1;
 private: System::Windows::Forms::Button^  button2;
 private: System::Windows::Forms::Button^  button3;
 private: System::Windows::Forms::Button^  button4;
 private: System::Windows::Forms::Button^  button5;
 private: System::Windows::Forms::Button^  button6;
 private: System::Windows::Forms::Button^  button7;


 protected:

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

#pragma region Windows Form Designer generated code
  /// <summary>
  /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
  /// コード エディターで変更しないでください。
  /// </summary>
  void InitializeComponent(void)
  {
   this->flowLayoutPanel1 = (gcnew System::Windows::Forms::FlowLayoutPanel());
   this->button1 = (gcnew System::Windows::Forms::Button());
   this->button2 = (gcnew System::Windows::Forms::Button());
   this->button3 = (gcnew System::Windows::Forms::Button());
   this->button4 = (gcnew System::Windows::Forms::Button());
   this->button5 = (gcnew System::Windows::Forms::Button());
   this->button6 = (gcnew System::Windows::Forms::Button());
   this->button7 = (gcnew System::Windows::Forms::Button());
   this->flowLayoutPanel1->SuspendLayout();
   this->SuspendLayout();
   //
   // flowLayoutPanel1
   //
   this->flowLayoutPanel1->Controls->Add(this->button1);
   this->flowLayoutPanel1->Controls->Add(this->button2);
   this->flowLayoutPanel1->Controls->Add(this->button3);
   this->flowLayoutPanel1->Controls->Add(this->button4);
   this->flowLayoutPanel1->Controls->Add(this->button5);
   this->flowLayoutPanel1->Controls->Add(this->button6);
   this->flowLayoutPanel1->Controls->Add(this->button7);
   this->flowLayoutPanel1->Dock = System::Windows::Forms::DockStyle::Fill;
   this->flowLayoutPanel1->Location = System::Drawing::Point(0, 0);
   this->flowLayoutPanel1->Name = L"flowLayoutPanel1";
   this->flowLayoutPanel1->Size = System::Drawing::Size(284, 261);
   this->flowLayoutPanel1->TabIndex = 0;
   //
   // button1
   //
   this->button1->Location = System::Drawing::Point(3, 3);
   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;
   //
   // button2
   //
   this->button2->Location = System::Drawing::Point(84, 3);
   this->button2->Name = L"button2";
   this->button2->Size = System::Drawing::Size(75, 23);
   this->button2->TabIndex = 1;
   this->button2->Text = L"button2";
   this->button2->UseVisualStyleBackColor = true;
   //
   // button3
   //
   this->button3->Location = System::Drawing::Point(165, 3);
   this->button3->Name = L"button3";
   this->button3->Size = System::Drawing::Size(75, 23);
   this->button3->TabIndex = 2;
   this->button3->Text = L"button3";
   this->button3->UseVisualStyleBackColor = true;
   //
   // button4
   //
   this->button4->Location = System::Drawing::Point(3, 32);
   this->button4->Name = L"button4";
   this->button4->Size = System::Drawing::Size(75, 23);
   this->button4->TabIndex = 3;
   this->button4->Text = L"button4";
   this->button4->UseVisualStyleBackColor = true;
   //
   // button5
   //
   this->button5->Location = System::Drawing::Point(84, 32);
   this->button5->Name = L"button5";
   this->button5->Size = System::Drawing::Size(75, 23);
   this->button5->TabIndex = 4;
   this->button5->Text = L"button5";
   this->button5->UseVisualStyleBackColor = true;
   //
   // button6
   //
   this->button6->Location = System::Drawing::Point(165, 32);
   this->button6->Name = L"button6";
   this->button6->Size = System::Drawing::Size(75, 23);
   this->button6->TabIndex = 5;
   this->button6->Text = L"button6";
   this->button6->UseVisualStyleBackColor = true;
   //
   // button7
   //
   this->button7->Location = System::Drawing::Point(3, 61);
   this->button7->Name = L"button7";
   this->button7->Size = System::Drawing::Size(75, 23);
   this->button7->TabIndex = 6;
   this->button7->Text = L"button7";
   this->button7->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->flowLayoutPanel1);
   this->Name = L"MyForm";
   this->Text = L"Hello C++/CLI World !!";
   this->flowLayoutPanel1->ResumeLayout(false);
   this->ResumeLayout(false);

  }
#pragma endregion

 };
}

 

 

 

 

 

 

最終更新:2013年10月06日 13:28