C++ > CLI:ボタン

基本プロジェクトに button を3つ配置します。


button2 のプロパティの Enabled を False にします。


button3 のプロパティの Cursor を Hand にします。


ビルドして実行してみましょう。
ボタン2が使用不可になっていて、ボタン3の上にマウスカーソルを
移動させるとマウスカーソルが手のカーソルに変化します。


今回も全くコードを記述せずにアプリが作成できましたね。
ちなみに、自動作成されるコードの方は以下の通りです。

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::Button^  button1;
 protected:
 private: System::Windows::Forms::Button^  button2;
 private: System::Windows::Forms::Button^  button3;

 protected:


 protected:

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

#pragma region Windows Form Designer generated code
  /// <summary>
  /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
  /// コード エディターで変更しないでください。
  /// </summary>
  void InitializeComponent(void)
  {
   this->button1 = (gcnew System::Windows::Forms::Button());
   this->button2 = (gcnew System::Windows::Forms::Button());
   this->button3 = (gcnew System::Windows::Forms::Button());
   this->SuspendLayout();
   //
   // button1
   //
   this->button1->Location = System::Drawing::Point(28, 53);
   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->Enabled = false;
   this->button2->Location = System::Drawing::Point(197, 118);
   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->Cursor = System::Windows::Forms::Cursors::Hand;
   this->button3->Location = System::Drawing::Point(111, 203);
   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;
   //
   // 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->button3);
   this->Controls->Add(this->button2);
   this->Controls->Add(this->button1);
   this->Name = L"MyForm";
   this->Text = L"Hello C++/CLI World !!";
   this->ResumeLayout(false);

  }
#pragma endregion

 };
}

 

 

 

 

 

 

最終更新:2013年09月09日 11:53