C++ > CLI:ツールストリップコンテナ

基本プロジェクトに ToolStripContainer を配置し、
フォームの四辺にドッキングするをクリックします。


このようになりました。


デフォルトではフォームの四辺の上側にツールバーを置くエリアがあります。
フォームの四辺にあるコンテナパネルをクリックするとツールストリップを
配置するエリアが現れます。
とりあえず、上側のエリアにツールストリップを配置します。


ツールバーにボタンとラベルを追加しました。


ビルドして実行してみましょう。
ツールバーのつまみをドラッグしてフォームの四辺に移動させると
ツールバーの位置を変える事ができます。

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::ToolStripContainer^  toolStripContainer1;
 private: System::Windows::Forms::ToolStrip^  toolStrip1;
 private: System::Windows::Forms::ToolStripButton^  toolStripButton1;
 private: System::Windows::Forms::ToolStripLabel^  toolStripLabel1;

 

 

 protected:


 protected:

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

#pragma region Windows Form Designer generated code
  /// <summary>
  /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
  /// コード エディターで変更しないでください。
  /// </summary>
  void InitializeComponent(void)
  {
   System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm::typeid));
   this->toolStripContainer1 = (gcnew System::Windows::Forms::ToolStripContainer());
   this->toolStrip1 = (gcnew System::Windows::Forms::ToolStrip());
   this->toolStripButton1 = (gcnew System::Windows::Forms::ToolStripButton());
   this->toolStripLabel1 = (gcnew System::Windows::Forms::ToolStripLabel());
   this->toolStripContainer1->TopToolStripPanel->SuspendLayout();
   this->toolStripContainer1->SuspendLayout();
   this->toolStrip1->SuspendLayout();
   this->SuspendLayout();
   //
   // toolStripContainer1
   //
   //
   // toolStripContainer1.ContentPanel
   //
   this->toolStripContainer1->ContentPanel->Size = System::Drawing::Size(284, 236);
   this->toolStripContainer1->Dock = System::Windows::Forms::DockStyle::Fill;
   this->toolStripContainer1->Location = System::Drawing::Point(0, 0);
   this->toolStripContainer1->Name = L"toolStripContainer1";
   this->toolStripContainer1->Size = System::Drawing::Size(284, 261);
   this->toolStripContainer1->TabIndex = 0;
   this->toolStripContainer1->Text = L"toolStripContainer1";
   //
   // toolStripContainer1.TopToolStripPanel
   //
   this->toolStripContainer1->TopToolStripPanel->Controls->Add(this->toolStrip1);
   //
   // toolStrip1
   //
   this->toolStrip1->Dock = System::Windows::Forms::DockStyle::None;
   this->toolStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->toolStripButton1,
    this->toolStripLabel1});
   this->toolStrip1->Location = System::Drawing::Point(3, 0);
   this->toolStrip1->Name = L"toolStrip1";
   this->toolStrip1->Size = System::Drawing::Size(161, 25);
   this->toolStrip1->TabIndex = 0;
   //
   // toolStripButton1
   //
   this->toolStripButton1->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
   this->toolStripButton1->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"toolStripButton1.Image")));
   this->toolStripButton1->ImageTransparentColor = System::Drawing::Color::Magenta;
   this->toolStripButton1->Name = L"toolStripButton1";
   this->toolStripButton1->Size = System::Drawing::Size(23, 22);
   this->toolStripButton1->Text = L"toolStripButton1";
   //
   // toolStripLabel1
   //
   this->toolStripLabel1->Name = L"toolStripLabel1";
   this->toolStripLabel1->Size = System::Drawing::Size(95, 22);
   this->toolStripLabel1->Text = L"toolStripLabel1";
   //
   // 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->toolStripContainer1);
   this->Name = L"MyForm";
   this->Text = L"Hello C++/CLI World !!";
   this->toolStripContainer1->TopToolStripPanel->ResumeLayout(false);
   this->toolStripContainer1->TopToolStripPanel->PerformLayout();
   this->toolStripContainer1->ResumeLayout(false);
   this->toolStripContainer1->PerformLayout();
   this->toolStrip1->ResumeLayout(false);
   this->toolStrip1->PerformLayout();
   this->ResumeLayout(false);

  }
#pragma endregion

 };
}
 

 

 

 

 

 

 

最終更新:2013年10月10日 16:42