C++ > CLI:メニュー

基本プロジェクトにメニューを配置します。


「ここへ入力」となっている所をクリックして「ファイル」と
入力します。


今回は適当に、それらしいメニューアイテムを入力してみます。


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

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::MenuStrip^  menuStrip1;
 protected:
 private: System::Windows::Forms::ToolStripMenuItem^  ファイルToolStripMenuItem;
 private: System::Windows::Forms::ToolStripMenuItem^  新規作成ToolStripMenuItem;
 private: System::Windows::Forms::ToolStripMenuItem^  開くToolStripMenuItem;
 private: System::Windows::Forms::ToolStripMenuItem^  保存ToolStripMenuItem;
 private: System::Windows::Forms::ToolStripMenuItem^  終了ToolStripMenuItem;
 private: System::Windows::Forms::ToolStripMenuItem^  編集ToolStripMenuItem;

 private: System::Windows::Forms::ToolStripMenuItem^  ツールToolStripMenuItem;
 private: System::Windows::Forms::ToolStripMenuItem^  オプションToolStripMenuItem;
 private: System::Windows::Forms::ToolStripMenuItem^  ヘルプToolStripMenuItem;


 protected:

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

#pragma region Windows Form Designer generated code
  /// <summary>
  /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
  /// コード エディターで変更しないでください。
  /// </summary>
  void InitializeComponent(void)
  {
   this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
   this->ファイルToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
   this->新規作成ToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
   this->開くToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
   this->保存ToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
   this->終了ToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
   this->編集ToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
   this->ツールToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
   this->オプションToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
   this->ヘルプToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
   this->menuStrip1->SuspendLayout();
   this->SuspendLayout();
   //
   // menuStrip1
   //
   this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(3) {this->ファイルToolStripMenuItem,
    this->編集ToolStripMenuItem, this->ヘルプToolStripMenuItem});
   this->menuStrip1->Location = System::Drawing::Point(0, 0);
   this->menuStrip1->Name = L"menuStrip1";
   this->menuStrip1->Size = System::Drawing::Size(284, 24);
   this->menuStrip1->TabIndex = 0;
   this->menuStrip1->Text = L"menuStrip1";
   //
   // ファイルToolStripMenuItem
   //
   this->ファイルToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(4) {this->新規作成ToolStripMenuItem,
    this->開くToolStripMenuItem, this->保存ToolStripMenuItem, this->終了ToolStripMenuItem});
   this->ファイルToolStripMenuItem->Name = L"ファイルToolStripMenuItem";
   this->ファイルToolStripMenuItem->Size = System::Drawing::Size(53, 20);
   this->ファイルToolStripMenuItem->Text = L"ファイル";
   //
   // 新規作成ToolStripMenuItem
   //
   this->新規作成ToolStripMenuItem->Name = L"新規作成ToolStripMenuItem";
   this->新規作成ToolStripMenuItem->Size = System::Drawing::Size(122, 22);
   this->新規作成ToolStripMenuItem->Text = L"新規作成";
   //
   // 開くToolStripMenuItem
   //
   this->開くToolStripMenuItem->Name = L"開くToolStripMenuItem";
   this->開くToolStripMenuItem->Size = System::Drawing::Size(122, 22);
   this->開くToolStripMenuItem->Text = L"開く";
   //
   // 保存ToolStripMenuItem
   //
   this->保存ToolStripMenuItem->Name = L"保存ToolStripMenuItem";
   this->保存ToolStripMenuItem->Size = System::Drawing::Size(122, 22);
   this->保存ToolStripMenuItem->Text = L"保存";
   //
   // 終了ToolStripMenuItem
   //
   this->終了ToolStripMenuItem->Name = L"終了ToolStripMenuItem";
   this->終了ToolStripMenuItem->Size = System::Drawing::Size(122, 22);
   this->終了ToolStripMenuItem->Text = L"終了";
   //
   // 編集ToolStripMenuItem
   //
   this->編集ToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->ツールToolStripMenuItem,
    this->オプションToolStripMenuItem});
   this->編集ToolStripMenuItem->Name = L"編集ToolStripMenuItem";
   this->編集ToolStripMenuItem->Size = System::Drawing::Size(43, 20);
   this->編集ToolStripMenuItem->Text = L"編集";
   //
   // ツールToolStripMenuItem
   //
   this->ツールToolStripMenuItem->Name = L"ツールToolStripMenuItem";
   this->ツールToolStripMenuItem->Size = System::Drawing::Size(152, 22);
   this->ツールToolStripMenuItem->Text = L"ツール";
   //
   // オプションToolStripMenuItem1
   //
   this->オプションToolStripMenuItem->Name = L"オプションToolStripMenuItem1";
   this->オプションToolStripMenuItem->Size = System::Drawing::Size(152, 22);
   this->オプションToolStripMenuItem->Text = L"オプション";
   //
   // ヘルプToolStripMenuItem
   //
   this->ヘルプToolStripMenuItem->Name = L"ヘルプToolStripMenuItem";
   this->ヘルプToolStripMenuItem->Size = System::Drawing::Size(48, 20);
   this->ヘルプToolStripMenuItem->Text = L"ヘルプ";
   //
   // 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->menuStrip1);
   this->MainMenuStrip = this->menuStrip1;
   this->Name = L"MyForm";
   this->Text = L"Hello C++/CLI World !!";
   this->menuStrip1->ResumeLayout(false);
   this->menuStrip1->PerformLayout();
   this->ResumeLayout(false);
   this->PerformLayout();

  }
#pragma endregion

 };
}

 

 

 

 

 

 

最終更新:2013年09月24日 01:17