読者です 読者をやめる 読者になる 読者になる

Awesome Hacks!

プログラミング初心者なので地道に勉強していきます。分からない人の立場から整理していきます。

Windowsアプリ開発_電卓

Visual C++で、一番初めに電卓を作ってみる。
 


カシオ計算機 CASIO 学校専用電卓 12桁 AZ-26S」というものが標準らしいので、この電卓に近づける感じで作っていく。
f:id:tamaking01:20150523114610j:plain
 

電卓の使い方

電卓の機能はこのページで確認できる。
カシオの電卓シュミレーター - 電卓を体験しよう - 電卓 - CASIO
履歴と「GT(グランドトータル)」機能 - なにしろ電卓の使い方
Web電卓/計算機アプリ(消費税学習機能・スマホキー配列)| 電卓アプリ
他にも、Googleで「電卓」と調べればGoogle電卓がすぐに使えるし、「web電卓」という名のインストール不要のブラウザ電卓が複数ある様子。
 
 

プログラミング!!

第6講 簡易電卓ソフト作りに挑戦しよう 第1話 簡易電卓Form1作り
 
上記サイトを参考に作成。
f:id:tamaking01:20150523133751p:plain
 
 
はっきりいって、自分で試行錯誤やるしかない。が、ロジック的な部分に苦戦した。
関数や電卓の動きについて調べるのにも時間を要した。その辺は自分の努力しだいとは違うので、上記サイトなどを参考にするとよいのではと思う。
 
また、一応下記にソースを記載するが、おそらく無駄な処理が多い。途中で少し飽きてきてしまったこともあり、表面的にしか動きを確認していないので、おそらく不具合が起こると思われる。(自己責任でお願いいたします。)あくまでも参考に。
 
大事なのは、電卓の作りたい機能をどうやって実現するのか自分で考えること、だと思う。
特に(自分も含め)慣れないうちは、効率や無駄など考えずに、同じ結果になることだけをまず追求すべきだと思う。実際、想定した動きになったときに喜びは大きい。
というのが、はじめてGUIアプリを今回作ってみての感想。
 
 

#pragma once


namespace 電卓 {

	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>
	/// Form1 の概要
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: ここにコンストラクター コードを追加します
			//
		}
		static String^ opeFlg = "";
		static String^ hourStr = "";
		static String^ minStr = "";
		static String^ secStr = "";
		static double sum = 0;
		static int c1Flg = 1; 
		static double mem = 0;
		static int mem1Flg = 0;
		static double gt = 0;
		static int tFlg = 0;
		static int hour = 0;
		static int min = 0;
		static int sec = 0;
		static long tSum = 0;
		static int tMinusFlg = 1;
		static int tInitFlg = 0;
	private: System::Windows::Forms::Label^  label1;
	protected:
		/// <summary>
		/// 使用中のリソースをすべてクリーンアップします。
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::TextBox^  textBox1;
	protected: 
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Button^  button2;
	private: System::Windows::Forms::Button^  button3;
	private: System::Windows::Forms::Button^  button4;
	private: System::Windows::Forms::Button^  button5;
	private: System::Windows::Forms::Button^  button6;
	private: System::Windows::Forms::Button^  button7;
	private: System::Windows::Forms::Button^  button8;
	private: System::Windows::Forms::Button^  button9;
	private: System::Windows::Forms::Button^  button10;
	private: System::Windows::Forms::Button^  button11;
	private: System::Windows::Forms::Button^  button12;
	private: System::Windows::Forms::Button^  button13;
	private: System::Windows::Forms::Button^  button14;
	private: System::Windows::Forms::Button^  button15;
	private: System::Windows::Forms::Button^  button16;
	private: System::Windows::Forms::Button^  button17;
	private: System::Windows::Forms::Button^  button18;
	private: System::Windows::Forms::Button^  button19;
	private: System::Windows::Forms::Button^  button20;
	private: System::Windows::Forms::Button^  button21;
	private: System::Windows::Forms::Button^  button22;
	private: System::Windows::Forms::Button^  button23;
	private: System::Windows::Forms::Button^  button24;
	private: System::Windows::Forms::Button^  button25;
	private: System::Windows::Forms::Button^  button26;
	private: System::Windows::Forms::Button^  button27;
	private: System::Windows::Forms::Button^  button28;
	private: System::Windows::Forms::Button^  button29;

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

#pragma region Windows Form Designer generated code
		/// <summary>
		/// デザイナー サポートに必要なメソッドです。このメソッドの内容を
		/// コード エディターで変更しないでください。
		/// </summary>
		void InitializeComponent(void)
		{
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->button3 = (gcnew System::Windows::Forms::Button());
			this->button4 = (gcnew System::Windows::Forms::Button());
			this->button5 = (gcnew System::Windows::Forms::Button());
			this->button6 = (gcnew System::Windows::Forms::Button());
			this->button7 = (gcnew System::Windows::Forms::Button());
			this->button8 = (gcnew System::Windows::Forms::Button());
			this->button9 = (gcnew System::Windows::Forms::Button());
			this->button10 = (gcnew System::Windows::Forms::Button());
			this->button11 = (gcnew System::Windows::Forms::Button());
			this->button12 = (gcnew System::Windows::Forms::Button());
			this->button13 = (gcnew System::Windows::Forms::Button());
			this->button14 = (gcnew System::Windows::Forms::Button());
			this->button15 = (gcnew System::Windows::Forms::Button());
			this->button16 = (gcnew System::Windows::Forms::Button());
			this->button17 = (gcnew System::Windows::Forms::Button());
			this->button18 = (gcnew System::Windows::Forms::Button());
			this->button19 = (gcnew System::Windows::Forms::Button());
			this->button20 = (gcnew System::Windows::Forms::Button());
			this->button21 = (gcnew System::Windows::Forms::Button());
			this->button22 = (gcnew System::Windows::Forms::Button());
			this->button23 = (gcnew System::Windows::Forms::Button());
			this->button24 = (gcnew System::Windows::Forms::Button());
			this->button25 = (gcnew System::Windows::Forms::Button());
			this->button26 = (gcnew System::Windows::Forms::Button());
			this->button27 = (gcnew System::Windows::Forms::Button());
			this->button28 = (gcnew System::Windows::Forms::Button());
			this->button29 = (gcnew System::Windows::Forms::Button());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->SuspendLayout();
			// 
			// textBox1
			// 
			this->textBox1->Font = (gcnew System::Drawing::Font(L"MS UI Gothic", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(128)));
			this->textBox1->Location = System::Drawing::Point(12, 12);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(234, 31);
			this->textBox1->TabIndex = 0;
			this->textBox1->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(66, 230);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(42, 33);
			this->button1->TabIndex = 1;
			this->button1->Text = L"1";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button2
			// 
			this->button2->Location = System::Drawing::Point(112, 230);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(42, 33);
			this->button2->TabIndex = 2;
			this->button2->Text = L"2";
			this->button2->UseVisualStyleBackColor = true;
			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
			// 
			// button3
			// 
			this->button3->Location = System::Drawing::Point(158, 230);
			this->button3->Name = L"button3";
			this->button3->Size = System::Drawing::Size(42, 33);
			this->button3->TabIndex = 3;
			this->button3->Text = L"3";
			this->button3->UseVisualStyleBackColor = true;
			this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
			// 
			// button4
			// 
			this->button4->Location = System::Drawing::Point(66, 189);
			this->button4->Name = L"button4";
			this->button4->Size = System::Drawing::Size(42, 33);
			this->button4->TabIndex = 4;
			this->button4->Text = L"4";
			this->button4->UseVisualStyleBackColor = true;
			this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
			// 
			// button5
			// 
			this->button5->Location = System::Drawing::Point(112, 189);
			this->button5->Name = L"button5";
			this->button5->Size = System::Drawing::Size(42, 33);
			this->button5->TabIndex = 5;
			this->button5->Text = L"5";
			this->button5->UseVisualStyleBackColor = true;
			this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
			// 
			// button6
			// 
			this->button6->Location = System::Drawing::Point(158, 189);
			this->button6->Name = L"button6";
			this->button6->Size = System::Drawing::Size(42, 33);
			this->button6->TabIndex = 6;
			this->button6->Text = L"6";
			this->button6->UseVisualStyleBackColor = true;
			this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click);
			// 
			// button7
			// 
			this->button7->Location = System::Drawing::Point(66, 148);
			this->button7->Name = L"button7";
			this->button7->Size = System::Drawing::Size(42, 33);
			this->button7->TabIndex = 7;
			this->button7->Text = L"7";
			this->button7->UseVisualStyleBackColor = true;
			this->button7->Click += gcnew System::EventHandler(this, &Form1::button7_Click);
			// 
			// button8
			// 
			this->button8->Location = System::Drawing::Point(112, 148);
			this->button8->Name = L"button8";
			this->button8->Size = System::Drawing::Size(42, 33);
			this->button8->TabIndex = 8;
			this->button8->Text = L"8";
			this->button8->UseVisualStyleBackColor = true;
			this->button8->Click += gcnew System::EventHandler(this, &Form1::button8_Click);
			// 
			// button9
			// 
			this->button9->Location = System::Drawing::Point(158, 148);
			this->button9->Name = L"button9";
			this->button9->Size = System::Drawing::Size(42, 33);
			this->button9->TabIndex = 9;
			this->button9->Text = L"9";
			this->button9->UseVisualStyleBackColor = true;
			this->button9->Click += gcnew System::EventHandler(this, &Form1::button9_Click);
			// 
			// button10
			// 
			this->button10->Location = System::Drawing::Point(12, 271);
			this->button10->Name = L"button10";
			this->button10->Size = System::Drawing::Size(49, 33);
			this->button10->TabIndex = 10;
			this->button10->Text = L"0";
			this->button10->UseVisualStyleBackColor = true;
			this->button10->Click += gcnew System::EventHandler(this, &Form1::button10_Click);
			// 
			// button11
			// 
			this->button11->Location = System::Drawing::Point(66, 271);
			this->button11->Name = L"button11";
			this->button11->Size = System::Drawing::Size(42, 33);
			this->button11->TabIndex = 11;
			this->button11->Text = L"00";
			this->button11->UseVisualStyleBackColor = true;
			this->button11->Click += gcnew System::EventHandler(this, &Form1::button11_Click);
			// 
			// button12
			// 
			this->button12->Location = System::Drawing::Point(112, 271);
			this->button12->Name = L"button12";
			this->button12->Size = System::Drawing::Size(42, 33);
			this->button12->TabIndex = 12;
			this->button12->Text = L".";
			this->button12->UseVisualStyleBackColor = true;
			this->button12->Click += gcnew System::EventHandler(this, &Form1::button12_Click);
			// 
			// button13
			// 
			this->button13->Location = System::Drawing::Point(158, 271);
			this->button13->Name = L"button13";
			this->button13->Size = System::Drawing::Size(42, 33);
			this->button13->TabIndex = 13;
			this->button13->Text = L"=";
			this->button13->UseVisualStyleBackColor = true;
			this->button13->Click += gcnew System::EventHandler(this, &Form1::button13_Click);
			// 
			// button14
			// 
			this->button14->Location = System::Drawing::Point(204, 230);
			this->button14->Name = L"button14";
			this->button14->Size = System::Drawing::Size(42, 74);
			this->button14->TabIndex = 14;
			this->button14->Text = L"+";
			this->button14->UseVisualStyleBackColor = true;
			this->button14->Click += gcnew System::EventHandler(this, &Form1::button14_Click);
			// 
			// button15
			// 
			this->button15->Location = System::Drawing::Point(204, 189);
			this->button15->Name = L"button15";
			this->button15->Size = System::Drawing::Size(42, 33);
			this->button15->TabIndex = 15;
			this->button15->Text = L"-";
			this->button15->UseVisualStyleBackColor = true;
			this->button15->Click += gcnew System::EventHandler(this, &Form1::button15_Click);
			// 
			// button16
			// 
			this->button16->Location = System::Drawing::Point(204, 148);
			this->button16->Name = L"button16";
			this->button16->Size = System::Drawing::Size(42, 33);
			this->button16->TabIndex = 16;
			this->button16->Text = L"×";
			this->button16->UseVisualStyleBackColor = true;
			this->button16->Click += gcnew System::EventHandler(this, &Form1::button16_Click);
			// 
			// button17
			// 
			this->button17->Location = System::Drawing::Point(204, 107);
			this->button17->Name = L"button17";
			this->button17->Size = System::Drawing::Size(42, 33);
			this->button17->TabIndex = 17;
			this->button17->Text = L"÷";
			this->button17->UseVisualStyleBackColor = true;
			this->button17->Click += gcnew System::EventHandler(this, &Form1::button17_Click);
			// 
			// button18
			// 
			this->button18->Location = System::Drawing::Point(12, 107);
			this->button18->Name = L"button18";
			this->button18->Size = System::Drawing::Size(42, 33);
			this->button18->TabIndex = 18;
			this->button18->Text = L"MC";
			this->button18->UseVisualStyleBackColor = true;
			this->button18->Click += gcnew System::EventHandler(this, &Form1::button18_Click);
			// 
			// button19
			// 
			this->button19->Location = System::Drawing::Point(66, 107);
			this->button19->Name = L"button19";
			this->button19->Size = System::Drawing::Size(42, 33);
			this->button19->TabIndex = 19;
			this->button19->Text = L"MR";
			this->button19->UseVisualStyleBackColor = true;
			this->button19->Click += gcnew System::EventHandler(this, &Form1::button19_Click);
			// 
			// button20
			// 
			this->button20->Location = System::Drawing::Point(112, 107);
			this->button20->Name = L"button20";
			this->button20->Size = System::Drawing::Size(42, 33);
			this->button20->TabIndex = 20;
			this->button20->Text = L"M-";
			this->button20->UseVisualStyleBackColor = true;
			this->button20->Click += gcnew System::EventHandler(this, &Form1::button20_Click);
			// 
			// button21
			// 
			this->button21->Location = System::Drawing::Point(158, 107);
			this->button21->Name = L"button21";
			this->button21->Size = System::Drawing::Size(42, 33);
			this->button21->TabIndex = 21;
			this->button21->Text = L"M+";
			this->button21->UseVisualStyleBackColor = true;
			this->button21->Click += gcnew System::EventHandler(this, &Form1::button21_Click);
			// 
			// button22
			// 
			this->button22->Location = System::Drawing::Point(12, 148);
			this->button22->Name = L"button22";
			this->button22->Size = System::Drawing::Size(42, 33);
			this->button22->TabIndex = 22;
			this->button22->Text = L"+/-";
			this->button22->UseVisualStyleBackColor = true;
			this->button22->Click += gcnew System::EventHandler(this, &Form1::button22_Click);
			// 
			// button23
			// 
			this->button23->Location = System::Drawing::Point(12, 189);
			this->button23->Name = L"button23";
			this->button23->Size = System::Drawing::Size(42, 33);
			this->button23->TabIndex = 23;
			this->button23->Text = L"AC";
			this->button23->UseVisualStyleBackColor = true;
			this->button23->Click += gcnew System::EventHandler(this, &Form1::button23_Click);
			// 
			// button24
			// 
			this->button24->Location = System::Drawing::Point(12, 230);
			this->button24->Name = L"button24";
			this->button24->Size = System::Drawing::Size(42, 33);
			this->button24->TabIndex = 24;
			this->button24->Text = L"C";
			this->button24->UseVisualStyleBackColor = true;
			this->button24->Click += gcnew System::EventHandler(this, &Form1::button24_Click);
			// 
			// button25
			// 
			this->button25->Location = System::Drawing::Point(12, 66);
			this->button25->Name = L"button25";
			this->button25->Size = System::Drawing::Size(49, 33);
			this->button25->TabIndex = 25;
			this->button25->Text = L"H/M/S";
			this->button25->UseVisualStyleBackColor = true;
			this->button25->Click += gcnew System::EventHandler(this, &Form1::button25_Click);
			// 
			// button26
			// 
			this->button26->Location = System::Drawing::Point(66, 66);
			this->button26->Name = L"button26";
			this->button26->Size = System::Drawing::Size(42, 33);
			this->button26->TabIndex = 26;
			this->button26->Text = L"%";
			this->button26->UseVisualStyleBackColor = true;
			this->button26->Click += gcnew System::EventHandler(this, &Form1::button26_Click);
			// 
			// button27
			// 
			this->button27->Location = System::Drawing::Point(112, 66);
			this->button27->Name = L"button27";
			this->button27->Size = System::Drawing::Size(42, 33);
			this->button27->TabIndex = 27;
			this->button27->Text = L"→";
			this->button27->UseVisualStyleBackColor = true;
			this->button27->Click += gcnew System::EventHandler(this, &Form1::button27_Click);
			// 
			// button28
			// 
			this->button28->Location = System::Drawing::Point(158, 66);
			this->button28->Name = L"button28";
			this->button28->Size = System::Drawing::Size(42, 33);
			this->button28->TabIndex = 28;
			this->button28->Text = L"√";
			this->button28->UseVisualStyleBackColor = true;
			this->button28->Click += gcnew System::EventHandler(this, &Form1::button28_Click);
			// 
			// button29
			// 
			this->button29->Location = System::Drawing::Point(204, 66);
			this->button29->Name = L"button29";
			this->button29->Size = System::Drawing::Size(42, 33);
			this->button29->TabIndex = 29;
			this->button29->Text = L"GT";
			this->button29->UseVisualStyleBackColor = true;
			this->button29->Click += gcnew System::EventHandler(this, &Form1::button29_Click);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->BackColor = System::Drawing::Color::White;
			this->label1->Font = (gcnew System::Drawing::Font(L"MS UI Gothic", 9, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(128)));
			this->label1->Location = System::Drawing::Point(13, 13);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(0, 12);
			this->label1->TabIndex = 30;
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(258, 315);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->button29);
			this->Controls->Add(this->button28);
			this->Controls->Add(this->button27);
			this->Controls->Add(this->button26);
			this->Controls->Add(this->button25);
			this->Controls->Add(this->button24);
			this->Controls->Add(this->button23);
			this->Controls->Add(this->button22);
			this->Controls->Add(this->button21);
			this->Controls->Add(this->button20);
			this->Controls->Add(this->button19);
			this->Controls->Add(this->button18);
			this->Controls->Add(this->button17);
			this->Controls->Add(this->button16);
			this->Controls->Add(this->button15);
			this->Controls->Add(this->button14);
			this->Controls->Add(this->button13);
			this->Controls->Add(this->button12);
			this->Controls->Add(this->button11);
			this->Controls->Add(this->button10);
			this->Controls->Add(this->button9);
			this->Controls->Add(this->button8);
			this->Controls->Add(this->button7);
			this->Controls->Add(this->button6);
			this->Controls->Add(this->button5);
			this->Controls->Add(this->button4);
			this->Controls->Add(this->button3);
			this->Controls->Add(this->button2);
			this->Controls->Add(this->button1);
			this->Controls->Add(this->textBox1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
				 textBox1->Text = sum.ToString();
			 }
			 // 「1」ボタン
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			if(tFlg == 0){
				if(c1Flg == 1){
					c1Flg = 0;
					textBox1->Text = L"1";
				}else{
					textBox1->Text += L"1";
				}
				if(opeFlg == "="){
					sum = 0;
					opeFlg = "";
				}
				if(mem1Flg == 1){
					sum = 0;
					mem1Flg = 0;
				}
			}else if(tFlg == 1 || tFlg == 4){
				minStr += L"1";					// 初回なら「001」、2回目は「011」、2回目は「111」になる
				minStr = minStr->Substring(1);	// インデックス「1」(2文字目)から2文字切り出し
				min = int::Parse(minStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 2 || tFlg == 5){
				secStr += L"1";					// 初回なら「001」、2回目は「011」、2回目は「111」になる
				secStr = secStr->Substring(1);	// インデックス「1」(2文字目)から2文字切り出し
				sec = int::Parse(secStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 3 && opeFlg != ""){
				// 時
				if(hourStr->Length > 5){
					return;
				}
				if(tInitFlg == 1){
					hour = 0;
					min = 0;
					sec = 0;
					minStr = L"00";
					secStr = L"00";
					tInitFlg = 0;
				}
				if(c1Flg == 1){
					c1Flg = 0;
					hourStr = L"1";
				}else{
					if(hourStr->Length <= 3){
						hourStr += L"1";
					}
				}
				hour = int::Parse(hourStr);
				textBox1->Text = hourStr + L"-" + minStr + L"'" + secStr + L"''";	
			}
		}
		 // 「2」ボタン
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
			if(tFlg == 0){
				if(c1Flg == 1){
					c1Flg = 0;
					textBox1->Text = L"2";
				}else{
					textBox1->Text += L"2";
				}
				if(opeFlg == "="){
					sum = 0;
					opeFlg = "";
				}
				if(mem1Flg == 1){
					sum = 0;
					mem1Flg = 0;
				}
			}else if(tFlg == 1 || tFlg == 4){
				minStr += L"2";
				minStr = minStr->Substring(1);
				min = int::Parse(minStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 2 || tFlg == 5){
				secStr += L"2";
				secStr = secStr->Substring(1);
				sec = int::Parse(secStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 3 && opeFlg != ""){
				// 時
				if(hourStr->Length > 5){
					return;
				}
				if(tInitFlg == 1){
					hour = 0;
					min = 0;
					sec = 0;
					minStr = L"00";
					secStr = L"00";
					tInitFlg = 0;
				}
				if(c1Flg == 1){
					c1Flg = 0;
					hourStr = L"2";
				}else{
					if(hourStr->Length <= 3){
						hourStr += L"2";
					}
				}
				hour = int::Parse(hourStr);
				textBox1->Text = hourStr + L"-" + minStr + L"'" + secStr + L"''";	
			}
		}
		 // 「3」ボタン
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
			if(tFlg == 0){
				if(c1Flg == 1){
					c1Flg = 0;
					textBox1->Text = L"3";
				}else{
					textBox1->Text += L"3";
				}
				if(opeFlg == "="){
					sum = 0;
					opeFlg = "";
				}
				if(mem1Flg == 1){
					sum = 0;
					mem1Flg = 0;
				}
			}else if(tFlg == 1 || tFlg == 4){
				minStr += L"3";
				minStr = minStr->Substring(1);
				min = int::Parse(minStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 2 || tFlg == 5){
				secStr += L"3";
				secStr = secStr->Substring(1);
				sec = int::Parse(secStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 3 && opeFlg != ""){
				// 時
				if(hourStr->Length > 5){
					return;
				}
				if(tInitFlg == 1){
					hour = 0;
					min = 0;
					sec = 0;
					minStr = L"00";
					secStr = L"00";
					tInitFlg = 0;
				}
				if(c1Flg == 1){
					c1Flg = 0;
					hourStr = L"3";
				}else{
					if(hourStr->Length <= 3){
						hourStr += L"3";
					}
				}
				hour = int::Parse(hourStr);
				textBox1->Text = hourStr + L"-" + minStr + L"'" + secStr + L"''";	
			}
		}
		 // 「4」ボタン
private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
			if(tFlg == 0){
				if(c1Flg == 1){
					c1Flg = 0;
					textBox1->Text = L"4";
				}else{
					textBox1->Text += L"4";
				}
				if(opeFlg == "="){
					sum = 0;
					opeFlg = "";
				}
				if(mem1Flg == 1){
					sum = 0;
					mem1Flg = 0;
				}
			}else if(tFlg == 1 || tFlg == 4){
				minStr += L"4";
				minStr = minStr->Substring(1);
				min = int::Parse(minStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 2 || tFlg == 5){
				secStr += L"4";
				secStr = secStr->Substring(1);
				sec = int::Parse(secStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 3 && opeFlg != ""){
				// 時
				if(hourStr->Length > 5){
					return;
				}
				if(tInitFlg == 1){
					hour = 0;
					min = 0;
					sec = 0;
					minStr = L"00";
					secStr = L"00";
					tInitFlg = 0;
				}
				if(c1Flg == 1){
					c1Flg = 0;
					hourStr = L"4";
				}else{
					if(hourStr->Length <= 3){
						hourStr += L"4";
					}
				}
				hour = int::Parse(hourStr);
				textBox1->Text = hourStr + L"-" + minStr + L"'" + secStr + L"''";	
			}
		}
		 // 「5」ボタン
private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
			if(tFlg == 0){
				if(c1Flg == 1){
					c1Flg = 0;
					textBox1->Text = L"5";
				}else{
					textBox1->Text += L"5";
				}
				if(opeFlg == "="){
					sum = 0;
					opeFlg = "";
				}
				if(mem1Flg == 1){
					sum = 0;
					mem1Flg = 0;
				}
			}else if(tFlg == 1 || tFlg == 4){
				minStr += L"5";
				minStr = minStr->Substring(1);
				min = int::Parse(minStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 2 || tFlg == 5){
				secStr += L"5";
				secStr = secStr->Substring(1);
				sec = int::Parse(secStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 3 && opeFlg != ""){
				// 時
				if(hourStr->Length > 5){
					return;
				}
				if(tInitFlg == 1){
					hour = 0;
					min = 0;
					sec = 0;
					minStr = L"00";
					secStr = L"00";
					tInitFlg = 0;
				}
				if(c1Flg == 1){
					c1Flg = 0;
					hourStr = L"5";
				}else{
					if(hourStr->Length <= 3){
						hourStr += L"5";
					}
				}
				hour = int::Parse(hourStr);
				textBox1->Text = hourStr + L"-" + minStr + L"'" + secStr + L"''";	
			}
		}
		 // 「6」ボタン
private: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e) {
			if(tFlg == 0){
				if(c1Flg == 1){
					c1Flg = 0;
					textBox1->Text = L"6";
				}else{
					textBox1->Text += L"6";
				}
				if(opeFlg == "="){
					sum = 0;
					opeFlg = "";
				}
				if(mem1Flg == 1){
					sum = 0;
					mem1Flg = 0;
				}
			}else if(tFlg == 1 || tFlg == 4){
				minStr += L"6";
				minStr = minStr->Substring(1);
				min = int::Parse(minStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 2 || tFlg == 5){
				secStr += L"6";
				secStr = secStr->Substring(1);
				sec = int::Parse(secStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 3 && opeFlg != ""){
				// 時
				if(hourStr->Length > 5){
					return;
				}
				if(tInitFlg == 1){
					hour = 0;
					min = 0;
					sec = 0;
					minStr = L"00";
					secStr = L"00";
					tInitFlg = 0;
				}
				if(c1Flg == 1){
					c1Flg = 0;
					hourStr = L"6";
				}else{
					if(hourStr->Length <= 3){
						hourStr += L"6";
					}
				}
				hour = int::Parse(hourStr);
				textBox1->Text = hourStr + L"-" + minStr + L"'" + secStr + L"''";	
			}
		}
		 // 「7」ボタン
private: System::Void button7_Click(System::Object^  sender, System::EventArgs^  e) {
			if(tFlg == 0){
				if(c1Flg == 1){
					c1Flg = 0;
					textBox1->Text = L"7";
				}else{
					textBox1->Text += L"7";
				}
				if(opeFlg == "="){
					sum = 0;
					opeFlg = "";
				}
				if(mem1Flg == 1){
					sum = 0;
					mem1Flg = 0;
				}
			}else if(tFlg == 1 || tFlg == 4){
				minStr += L"7";
				minStr = minStr->Substring(1);
				min = int::Parse(minStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 2 || tFlg == 5){
				secStr += L"7";
				secStr = secStr->Substring(1);
				sec = int::Parse(secStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 3 && opeFlg != ""){
				// 時
				if(hourStr->Length > 5){
					return;
				}
				if(tInitFlg == 1){
					hour = 0;
					min = 0;
					sec = 0;
					minStr = L"00";
					secStr = L"00";
					tInitFlg = 0;
				}
				if(c1Flg == 1){
					c1Flg = 0;
					hourStr = L"7";
				}else{
					if(hourStr->Length <= 3){
						hourStr += L"7";
					}
				}
				hour = int::Parse(hourStr);
				textBox1->Text = hourStr + L"-" + minStr + L"'" + secStr + L"''";	
			}
		}
		 // 「8」ボタン
private: System::Void button8_Click(System::Object^  sender, System::EventArgs^  e) {
			if(tFlg == 0){
				if(c1Flg == 1){
					c1Flg = 0;
					textBox1->Text = L"8";
				}else{
					textBox1->Text += L"8";
				}
				if(opeFlg == "="){
					sum = 0;
					opeFlg = "";
				}
				if(mem1Flg == 1){
					sum = 0;
					mem1Flg = 0;
				}
			}else if(tFlg == 1 || tFlg == 4){
				minStr += L"8";
				minStr = minStr->Substring(1);
				min = int::Parse(minStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 2 || tFlg == 5){
				secStr += L"8";
				secStr = secStr->Substring(1);
				sec = int::Parse(secStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 3 && opeFlg != ""){
				// 時
				if(hourStr->Length > 5){
					return;
				}
				if(tInitFlg == 1){
					hour = 0;
					min = 0;
					sec = 0;
					minStr = L"00";
					secStr = L"00";
					tInitFlg = 0;
				}
				if(c1Flg == 1){
					c1Flg = 0;
					hourStr = L"8";
				}else{
					if(hourStr->Length <= 3){
						hourStr += L"8";
					}
				}
				hour = int::Parse(hourStr);
				textBox1->Text = hourStr + L"-" + minStr + L"'" + secStr + L"''";	
			}
		}
		 // 「9」ボタン
private: System::Void button9_Click(System::Object^  sender, System::EventArgs^  e) {
			if(tFlg == 0){
				if(c1Flg == 1){
					c1Flg = 0;
					textBox1->Text = L"9";
				}else{
					textBox1->Text += L"9";
				}
				if(opeFlg == "="){
					sum = 0;
					opeFlg = "";
				}
				if(mem1Flg == 1){
					sum = 0;
					mem1Flg = 0;
				}
			}else if(tFlg == 1 || tFlg == 4){
				minStr += L"9";					// 初回なら「009」になる
				minStr = minStr->Substring(1);	// インデックス「1」から2文字
				min = int::Parse(minStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 2 || tFlg == 5){
				secStr += L"9";					// 初回なら「009」になる
				secStr = secStr->Substring(1);	// インデックス「1」から2文字
				sec = int::Parse(secStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 3 && opeFlg != ""){
				// 時
				if(hourStr->Length > 5){
					return;
				}
				if(tInitFlg == 1){
					hour = 0;
					min = 0;
					sec = 0;
					minStr = L"00";
					secStr = L"00";
					tInitFlg = 0;
				}
				if(c1Flg == 1){
					c1Flg = 0;
					hourStr = L"9";
				}else{
					if(hourStr->Length <= 3){
						hourStr += L"9";
					}
				}
				hour = int::Parse(hourStr);
				textBox1->Text = hourStr + L"-" + minStr + L"'" + secStr + L"''";
			}
		}
		// 「0」ボタン
private: System::Void button10_Click(System::Object^  sender, System::EventArgs^  e) {
			if(textBox1->Text != "0" && c1Flg != 1 && tFlg == 0){
				 textBox1->Text += L"0";
			}else if(tFlg == 1 || tFlg == 4){
				minStr += L"0";					// 初回なら「009」になる
				minStr = minStr->Substring(1);	// インデックス「1」から2文字
				min = int::Parse(minStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 2 || tFlg == 5){
				secStr += L"0";					// 初回なら「009」になる
				secStr = secStr->Substring(1);	// インデックス「1」から2文字
				sec = int::Parse(secStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 3 && opeFlg != ""){
				// 時
				if(hourStr->Length > 5){
					return;
				}
				if(tInitFlg == 1){
					hour = 0;
					min = 0;
					sec = 0;
					minStr = L"00";
					secStr = L"00";
					tInitFlg = 0;
				}
				if(c1Flg == 1){
				}else{
					if(hourStr->Length <= 3){
						hourStr += L"0";
					}
				}
				hour = int::Parse(hourStr);
				textBox1->Text = hourStr + L"-" + minStr + L"'" + secStr + L"''";
			}
		 }
		 // 「00」ボタン
private: System::Void button11_Click(System::Object^  sender, System::EventArgs^  e) {
			if(textBox1->Text != "0" && c1Flg != 1 && tFlg == 0){
				 textBox1->Text += L"00";
			}else if(tFlg == 1 || tFlg == 4){
				minStr += L"00";					// 初回なら「009」になる
				minStr = minStr->Substring(1);	// インデックス「1」から2文字
				min = int::Parse(minStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 2 || tFlg == 5){
				secStr += L"00";					// 初回なら「009」になる
				secStr = secStr->Substring(1);	// インデックス「1」から2文字
				sec = int::Parse(secStr);
				textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
			}else if(tFlg == 3 && opeFlg != ""){
				// 時
				if(hourStr->Length > 5){
					return;
				}
				if(tInitFlg == 1){
					hour = 0;
					min = 0;
					sec = 0;
					minStr = L"00";
					secStr = L"00";
					tInitFlg = 0;
				}
				if(c1Flg == 1){
				}else{
					if(hourStr->Length <= 2){
						hourStr += L"00";
					}
				}
				hour = int::Parse(hourStr);
				textBox1->Text = hourStr + L"-" + minStr + L"'" + secStr + L"''";
			}
		 }
		 // 「.」ボタン
private: System::Void button12_Click(System::Object^  sender, System::EventArgs^  e) {
			 if((textBox1->Text)->Contains(".") == false && tFlg == 0){
				 textBox1->Text += L".";
				 c1Flg = 0;
			 }
		 }
		 // 「=」ボタン
private: System::Void button13_Click(System::Object^  sender, System::EventArgs^  e) {
			if(tFlg == 0){
				calc(double::Parse(textBox1->Text));
				gt += sum;
			} else {
				tcalc((hour * 60 + min) * 60 + sec);
				opeFlg = L"=";
			}
		 }
		 // 「+」ボタン
private: System::Void button14_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(c1Flg != 1 && tFlg == 0){
				 calc(double::Parse(textBox1->Text));
			 }
			 opeFlg = L"+";
		 }
		 // 「-」ボタン
private: System::Void button15_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(c1Flg != 1 && tFlg == 0){
				 calc(double::Parse(textBox1->Text));
			 }
			 opeFlg = L"-";
		 }
		 // 「×」ボタン
private: System::Void button16_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(c1Flg != 1 && tFlg == 0){
				calc(double::Parse(textBox1->Text));
				opeFlg = L"*";
			 }
		 }
		 // 「÷」ボタン
private: System::Void button17_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(c1Flg != 1 && tFlg == 0){
				calc(double::Parse(textBox1->Text));
				opeFlg = L"/";
			 }
		 }
		 // calc関数
private: void calc(double num) {
			 if(opeFlg == ""){
				 sum = num;
			 }else if(opeFlg == "+"){
				 sum += num;
			 }else if(opeFlg == "-"){
				 sum -= num;
			 }else if(opeFlg == "*"){
				 sum *= num;
			 }else if(opeFlg == "/"){
				 sum /= num;
			 }
			 c1Flg = 1;
			 textBox1->Text = sum.ToString();
		 }
private: void tcalc(long num) {
			 if(opeFlg == ""){
				// 想定しない
			 }else if(opeFlg == "+"){
				 tSum += num;
			 }else if(opeFlg == "-"){
				if(tSum>=num){
					tSum -= num;
				}else{
					num -= tSum;
					tSum = num;
					tMinusFlg = -1;
				}
			 }

			 sec = tSum % 60;
			 hour = tSum / 3600 * tMinusFlg;
			 min = (tSum - (hour * 3600)) / 60; 
			 hourStr = hour.ToString();
			 minStr = min.ToString();
			 secStr = sec.ToString();
//			 c1Flg = 1;
			 textBox1->Text = hourStr + L"-" + minStr + L"'" + secStr + L"''";
		 }
		 // 「MC」ボタン
private: System::Void button18_Click(System::Object^  sender, System::EventArgs^  e) {
			mem = 0;
			label1->Text = "";
			mem1Flg = 0;
			gt = 0;
			hourStr = "";
			minStr = "";
			secStr = "";

			tFlg = 0;
			hour = 0;
			min = 0;
			sec = 0;
			tSum = 0;
			tMinusFlg = 1;
			tInitFlg = 0;
		 }
		 // 「MR」ボタン
private: System::Void button19_Click(System::Object^  sender, System::EventArgs^  e) {
			 textBox1->Text = mem.ToString();
		 }
		 // 「M-」ボタン
private: System::Void button20_Click(System::Object^  sender, System::EventArgs^  e) {
			 calc(double::Parse(textBox1->Text));
			 mem -= sum;
			 label1->Text = L"M";
			 mem1Flg = 1;
		 }
		 // 「M+」ボタン
private: System::Void button21_Click(System::Object^  sender, System::EventArgs^  e) {
			 calc(double::Parse(textBox1->Text));
			 mem += sum;
			 label1->Text = L"M";
			 mem1Flg = 1;
		 }
		 // 「+/-」ボタン
private: System::Void button22_Click(System::Object^  sender, System::EventArgs^  e) {
		 }
		 // 「AC」ボタン
private: System::Void button23_Click(System::Object^  sender, System::EventArgs^  e) {
			 clear();
		 }
		 // 「C」ボタン
private: System::Void button24_Click(System::Object^  sender, System::EventArgs^  e) {
			 textBox1->Text = L"0";
			 c1Flg = 1;
		 }
		 // clear関数
private: void clear() {
			 sum = 0;
			 opeFlg = "";
			 textBox1->Text = L"0";
			 c1Flg = 1;
		 }
		 // 「H/M/S」ボタン
private: System::Void button25_Click(System::Object^  sender, System::EventArgs^  e) {
			if(tFlg == 0){
				// 時
				if((textBox1->Text)->Length > 5){
					return;
				}
				hourStr = textBox1->Text;
				minStr = L"00";
				secStr = L"00";
				hour = int::Parse(textBox1->Text);
				tFlg = 1;
			}else if(tFlg == 1){
				// 分
				tFlg = 2;
			}else if(tFlg == 2){
				// 秒
				tFlg = 3;
				tInitFlg = 1; 
				c1Flg = 1;
				tSum = (hour * 60 + min) * 60 + sec;
			}else if(tFlg == 3){
				if(c1Flg == 0){
					tFlg = 4;
				}
			}else if(tFlg == 4){
				// 分
				tFlg = 5;
			}else if(tFlg == 5){
				// 秒
				tFlg = 6;
			}
			textBox1->Text = hour.ToString() + L"-" + minStr + L"'" + secStr + L"''";
		}
		// 「%」ボタン
private: System::Void button26_Click(System::Object^  sender, System::EventArgs^  e) {
			 textBox1->Text = (double::Parse(textBox1->Text) / 100).ToString();
		 }
		 // 「→」ボタン
private: System::Void button27_Click(System::Object^  sender, System::EventArgs^  e) {
			 int len = (textBox1->Text)->Length;
			 String^ tmpStr = (textBox1->Text)->Substring(0, len - 1);
			 if(tmpStr == ""){
				 textBox1->Text = L"0";
			 } else {
				 textBox1->Text = tmpStr;
			 }
			 if(tmpStr = "0"){
				 c1Flg = 1;
			 }
		 }
		 // 「√」ボタン
private: System::Void button28_Click(System::Object^  sender, System::EventArgs^  e) {
			 textBox1->Text = (Math::Sqrt(double::Parse(textBox1->Text))).ToString();
		 }
		 // 「GT」ボタン
private: System::Void button29_Click(System::Object^  sender, System::EventArgs^  e) {
			 textBox1->Text = gt.ToString();
		 }
};
}



20150518現在の作成画像
f:id:tamaking01:20150518021726p:plain
 
上記を作り直して・・・
 
20150524現在(完成?)の画像
f:id:tamaking01:20150524001109p:plain
※なんとか時間計算もできるようにした