#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;


namespace VC01
{
	/// <summary> 
	/// VC01 の概要
	///
	/// 警告 : このクラスの名前を変更する場合、このクラスが依存するすべての .resx ファイルに関連付けられた 
	///          マネージ リソース コンパイラ ツールに対して 'Resource File Name' プロパティを 
	///          変更する必要があります。この変更を行わないと、
	///          デザイナと、このフォームに関連付けられたローカライズ済みリソースとが、
	///          正しく相互に利用できなくなります。
	/// </summary>
public __gc class frm0311VC01 : public System::Windows::Forms::Form
{
public: 
	frm0311VC01(void)
	{
		InitializeComponent();
	}

protected: 
	void Dispose(Boolean disposing)
	{
		if (disposing && components)
		{
			components->Dispose();
		}
		__super::Dispose(disposing);
	}
private: System::Windows::Forms::TextBox *  txtNum1;
private: System::Windows::Forms::ComboBox *  cboTerm;
private: System::Windows::Forms::TextBox *  txtNum2;
private: System::Windows::Forms::Button *  cmdCalc;
private: System::Windows::Forms::TextBox *  txtAns;

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

	/// <summary>
	/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
	/// コード エディタで変更しないでください。
	/// </summary>
	void InitializeComponent(void)
	{
		this->txtNum1 = new System::Windows::Forms::TextBox();
		this->cboTerm = new System::Windows::Forms::ComboBox();
		this->txtNum2 = new System::Windows::Forms::TextBox();
		this->cmdCalc = new System::Windows::Forms::Button();
		this->txtAns = new System::Windows::Forms::TextBox();
		this->SuspendLayout();
		// 
		// txtNum1
		// 
		this->txtNum1->BackColor = System::Drawing::SystemColors::Window;
		this->txtNum1->Location = System::Drawing::Point(64, 8);
		this->txtNum1->MaxLength = 10;
		this->txtNum1->Name = S"txtNum1";
		this->txtNum1->Size = System::Drawing::Size(216, 19);
		this->txtNum1->TabIndex = 0;
		this->txtNum1->Text = S"txtNum1";
		this->txtNum1->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
		this->txtNum1->KeyPress += new System::Windows::Forms::KeyPressEventHandler(this, subNumCheck);
		this->txtNum1->Leave += new System::EventHandler(this, subLostFocus);
		this->txtNum1->Enter += new System::EventHandler(this, subGotFocus);
		// 
		// cboTerm
		// 
		this->cboTerm->Location = System::Drawing::Point(8, 32);
		this->cboTerm->Name = S"cboTerm";
		this->cboTerm->Size = System::Drawing::Size(48, 20);
		this->cboTerm->TabIndex = 1;
		this->cboTerm->Text = S"cboTerm";
		this->cboTerm->Leave += new System::EventHandler(this, subLostFocus);
		this->cboTerm->Enter += new System::EventHandler(this, subGotFocus);
		// 
		// txtNum2
		// 
		this->txtNum2->Location = System::Drawing::Point(64, 32);
		this->txtNum2->MaxLength = 10;
		this->txtNum2->Name = S"txtNum2";
		this->txtNum2->Size = System::Drawing::Size(216, 19);
		this->txtNum2->TabIndex = 2;
		this->txtNum2->Text = S"txtNum2";
		this->txtNum2->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
		this->txtNum2->KeyPress += new System::Windows::Forms::KeyPressEventHandler(this, subNumCheck);
		this->txtNum2->Leave += new System::EventHandler(this, subLostFocus);
		this->txtNum2->Enter += new System::EventHandler(this, subGotFocus);
		// 
		// cmdCalc
		// 
		this->cmdCalc->Location = System::Drawing::Point(8, 56);
		this->cmdCalc->Name = S"cmdCalc";
		this->cmdCalc->Size = System::Drawing::Size(272, 24);
		this->cmdCalc->TabIndex = 3;
		this->cmdCalc->Text = S"計算(&C)";
		this->cmdCalc->Click += new System::EventHandler(this, cmdCalc_Click);
		// 
		// txtAns
		// 
		this->txtAns->Location = System::Drawing::Point(64, 88);
		this->txtAns->Name = S"txtAns";
		this->txtAns->ReadOnly = true;
		this->txtAns->Size = System::Drawing::Size(216, 19);
		this->txtAns->TabIndex = 4;
		this->txtAns->Text = S"txtAns";
		this->txtAns->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
		// 
		// frm0311VC01
		// 
		this->AutoScaleBaseSize = System::Drawing::Size(5, 12);
		this->ClientSize = System::Drawing::Size(288, 118);
		this->Controls->Add(this->txtAns);
		this->Controls->Add(this->cmdCalc);
		this->Controls->Add(this->txtNum2);
		this->Controls->Add(this->cboTerm);
		this->Controls->Add(this->txtNum1);
		this->Name = S"frm0311VC01";
		this->Text = S"VC++.NET Form Sample 1";
		this->Load += new System::EventHandler(this, frm0311VC01_Load);
		this->ResumeLayout(false);

	}		
private: System::Void frm0311VC01_Load(System::Object *  sender, 
			 System::EventArgs *  e)
		 {
			 // 演算子の設定
			 this->cboTerm->DropDownStyle = ComboBoxStyle::DropDownList;
			 this->cboTerm->BeginUpdate();
			 this->cboTerm->Items->Clear();
			 this->cboTerm->Items->Add(S"＋");
			 this->cboTerm->Items->Add(S"−");
			 this->cboTerm->Items->Add(S"×");
			 this->cboTerm->Items->Add(S"÷");
			 this->cboTerm->EndUpdate();
			 // フィールドの初期化
			 this->txtNum1->Text = S"";
			 this->txtNum2->Text = S"";
			 this->txtAns->Text = S"";
		 }

private: System::Void subNumCheck(System::Object *  sender, 
			 System::Windows::Forms::KeyPressEventArgs *  e)
		 {
			 if (e->KeyChar == '.') 
			 {
				 // 小数点は１つだけ許可する
				 if (dynamic_cast<TextBox*>(sender)->Text->IndexOf('.')>0) 
				 {
					 e->Handled = true;
				 }
			 } 
			 else if ((e->KeyChar < '0' || e->KeyChar > '9') && 
				 (e->KeyChar != '\b'))
			 { 
				 // 数字とBS以外はキャンセル(delや→でKeypressは発生しない)
				 e->Handled = true;
			 }
		 }

private: System::Void subGotFocus(System::Object *  sender, 
			 System::EventArgs *  e)
		 {
			 // ハイライト表示
			 dynamic_cast<Control*>(sender)->BackColor = System::Drawing::Color::Lime;
		 }

private: System::Void subLostFocus(System::Object *  sender, 
			 System::EventArgs *  e)
		 {
			 // ハイライト非表示
			 dynamic_cast<Control*>(sender)->BackColor = System::Drawing::SystemColors::Info;
		 }

private: System::Void cmdCalc_Click(System::Object *  sender, 
			 System::EventArgs *  e)
		 {
			 double dblNum1;
			 double dblNum2;
			 //2値チェック
			 try {
				 dblNum1 = System::Convert::ToDouble(this->txtNum1->Text);
				 try{
					 dblNum2 = System::Convert::ToDouble(this->txtNum2->Text);
					 // 演算
					 if (String::Compare(this->cboTerm->Text,S"＋") == 0) {
						 this->txtAns->Text = System::Convert::ToString(dblNum1 + dblNum2);
					 } else if (String::Compare(this->cboTerm->Text,S"−") == 0) {
						 this->txtAns->Text = System::Convert::ToString(dblNum1 - dblNum2);
					 } else if (String::Compare(this->cboTerm->Text,S"×") == 0) {
						 this->txtAns->Text = System::Convert::ToString(dblNum1 * dblNum2);
					 } else if (String::Compare(this->cboTerm->Text,S"÷") == 0) {
						 this->txtAns->Text = System::Convert::ToString(dblNum1 / dblNum2);
					 } else {
						 MessageBox::Show(S"演算子を選択してください。", 
							 this->Text, 
							 MessageBoxButtons::OK, 
							 MessageBoxIcon::Warning);
					 }
				 }
				 catch(System::Exception *e)
				 {
					 MessageBox::Show(S"数値を指定してください。", 
						 this->Text, 
						 MessageBoxButtons::OK, 
						 MessageBoxIcon::Warning);
					 this->txtNum2->Focus();
				 }
			 }
			 catch(System::Exception *e)
			 {
				 MessageBox::Show(S"数値を指定してください。", 
					 this->Text, 
					 MessageBoxButtons::OK, 
					 MessageBoxIcon::Warning);
				 this->txtNum1->Focus();
			 }
		 }
};
}
