C++ > CLI:ツールバー

基本プロジェクトにツールバーを配置します。


プロパティの ImageScaling を Width 32、Height 32 にします。


ツールバーの左端にプルダウンメニューがあるので Button を追加します。


ボタンの Image をクリックして各種アイコンを設定します。
*設定の仕方に Visual Studio 2012 のアイコンライブラリーの入手方法が
あるので参考にしてください。
今回は、Visual Studio 2012 アイコンライブラリーを Cドライブにインストールし、
C:\VS2012 Modern Image Library\x--archive--x\Objects - VS2012\png_format\Office and VS\
にある画像を使いました。

後は適当にボタンとかセパレーターとかを追加しておきます。
ビルドして実行してみましょう。

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::ToolStrip^  toolStrip1;
 protected:
 private: System::Windows::Forms::ToolStripButton^  toolStripButton1;
 private: System::Windows::Forms::ToolStripButton^  toolStripButton2;
 private: System::Windows::Forms::ToolStripButton^  toolStripButton3;
 private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator1;
 private: System::Windows::Forms::ToolStripButton^  toolStripButton4;
 private: System::Windows::Forms::ToolStripButton^  toolStripButton5;
 private: System::Windows::Forms::ToolStripButton^  toolStripButton6;


 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->toolStrip1 = (gcnew System::Windows::Forms::ToolStrip());
   this->toolStripButton1 = (gcnew System::Windows::Forms::ToolStripButton());
   this->toolStripButton2 = (gcnew System::Windows::Forms::ToolStripButton());
   this->toolStripButton3 = (gcnew System::Windows::Forms::ToolStripButton());
   this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
   this->toolStripButton4 = (gcnew System::Windows::Forms::ToolStripButton());
   this->toolStripButton5 = (gcnew System::Windows::Forms::ToolStripButton());
   this->toolStripButton6 = (gcnew System::Windows::Forms::ToolStripButton());
   this->toolStrip1->SuspendLayout();
   this->SuspendLayout();
   //
   // toolStrip1
   //
   this->toolStrip1->ImageScalingSize = System::Drawing::Size(32, 32);
   this->toolStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(7) {this->toolStripButton1,
    this->toolStripButton2, this->toolStripButton3, this->toolStripSeparator1, this->toolStripButton4, this->toolStripButton5, this->toolStripButton6});
   this->toolStrip1->Location = System::Drawing::Point(0, 0);
   this->toolStrip1->Name = L"toolStrip1";
   this->toolStrip1->Size = System::Drawing::Size(284, 39);
   this->toolStrip1->TabIndex = 0;
   this->toolStrip1->Text = L"toolStrip1";
   //
   // 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(36, 36);
   this->toolStripButton1->Text = L"toolStripButton1";
   //
   // toolStripButton2
   //
   this->toolStripButton2->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
   this->toolStripButton2->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"toolStripButton2.Image")));
   this->toolStripButton2->ImageTransparentColor = System::Drawing::Color::Magenta;
   this->toolStripButton2->Name = L"toolStripButton2";
   this->toolStripButton2->Size = System::Drawing::Size(36, 36);
   this->toolStripButton2->Text = L"toolStripButton2";
   //
   // toolStripButton3
   //
   this->toolStripButton3->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
   this->toolStripButton3->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"toolStripButton3.Image")));
   this->toolStripButton3->ImageTransparentColor = System::Drawing::Color::Magenta;
   this->toolStripButton3->Name = L"toolStripButton3";
   this->toolStripButton3->Size = System::Drawing::Size(36, 36);
   this->toolStripButton3->Text = L"toolStripButton3";
   //
   // toolStripSeparator1
   //
   this->toolStripSeparator1->Name = L"toolStripSeparator1";
   this->toolStripSeparator1->Size = System::Drawing::Size(6, 39);
   //
   // toolStripButton4
   //
   this->toolStripButton4->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
   this->toolStripButton4->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"toolStripButton4.Image")));
   this->toolStripButton4->ImageTransparentColor = System::Drawing::Color::Magenta;
   this->toolStripButton4->Name = L"toolStripButton4";
   this->toolStripButton4->Size = System::Drawing::Size(36, 36);
   this->toolStripButton4->Text = L"toolStripButton4";
   //
   // toolStripButton5
   //
   this->toolStripButton5->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
   this->toolStripButton5->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"toolStripButton5.Image")));
   this->toolStripButton5->ImageTransparentColor = System::Drawing::Color::Magenta;
   this->toolStripButton5->Name = L"toolStripButton5";
   this->toolStripButton5->Size = System::Drawing::Size(36, 36);
   this->toolStripButton5->Text = L"toolStripButton5";
   //
   // toolStripButton6
   //
   this->toolStripButton6->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
   this->toolStripButton6->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"toolStripButton6.Image")));
   this->toolStripButton6->ImageTransparentColor = System::Drawing::Color::Magenta;
   this->toolStripButton6->Name = L"toolStripButton6";
   this->toolStripButton6->Size = System::Drawing::Size(36, 36);
   this->toolStripButton6->Text = L"toolStripButton6";
   //
   // 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->toolStrip1);
   this->Name = L"MyForm";
   this->Text = L"Hello C++/CLI World !!";
   this->toolStrip1->ResumeLayout(false);
   this->toolStrip1->PerformLayout();
   this->ResumeLayout(false);
   this->PerformLayout();

  }
#pragma endregion

 };
}

 

 

 

 

 

 

最終更新:2013年09月24日 21:47