#pragma once
namespace SimpleCalc {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
///
/// Form1 の概要
///
/// 警告: このクラスの名前を変更する場合、このクラスが依存するすべての .resx ファイルに関連付けられた
/// マネージ リソース コンパイラ ツールに対して 'Resource File Name' プロパティを
/// 変更する必要があります。この変更を行わないと、
/// デザイナと、このフォームに関連付けられたローカライズ済みリソースとが、
/// 正しく相互に利用できなくなります。
///
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: ここにコンストラクタ コードを追加します
//
}
protected:
///
/// 使用中のリソースをすべてクリーンアップします。
///
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ Input1TextBox;
protected:
protected:
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::TextBox^ Input2TextBox;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Button^ CalcButton;
private: System::Windows::Forms::TextBox^ AnswerTextBox;
private:
///
/// 必要なデザイナ変数です。
///
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
///
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
///
void InitializeComponent(void)
{
this->Input1TextBox = (gcnew System::Windows::Forms::TextBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->Input2TextBox = (gcnew System::Windows::Forms::TextBox());
this->label2 = (gcnew System::Windows::Forms::Label());
this->CalcButton = (gcnew System::Windows::Forms::Button());
this->AnswerTextBox = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// Input1TextBox
//
this->Input1TextBox->Location = System::Drawing::Point(13, 13);
this->Input1TextBox->Name = L"Input1TextBox";
this->Input1TextBox->Size = System::Drawing::Size(100, 19);
this->Input1TextBox->TabIndex = 0;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(121, 16);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(11, 12);
this->label1->TabIndex = 1;
this->label1->Text = L"+";
//
// Input2TextBox
//
this->Input2TextBox->Location = System::Drawing::Point(138, 13);
this->Input2TextBox->Name = L"Input2TextBox";
this->Input2TextBox->Size = System::Drawing::Size(100, 19);
this->Input2TextBox->TabIndex = 2;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(244, 16);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(11, 12);
this->label2->TabIndex = 3;
this->label2->Text = L"=";
//
// CalcButton
//
this->CalcButton->Location = System::Drawing::Point(13, 46);
this->CalcButton->Name = L"CalcButton";
this->CalcButton->Size = System::Drawing::Size(349, 23);
this->CalcButton->TabIndex = 4;
this->CalcButton->Text = L"計算する";
this->CalcButton->UseVisualStyleBackColor = true;
this->CalcButton->Click += gcnew System::EventHandler(this, &Form1::CalcButton_Click);
//
// AnswerTextBox
//
this->AnswerTextBox->Location = System::Drawing::Point(262, 13);
this->AnswerTextBox->Name = L"AnswerTextBox";
this->AnswerTextBox->Size = System::Drawing::Size(100, 19);
this->AnswerTextBox->TabIndex = 5;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(385, 81);
this->Controls->Add(this->AnswerTextBox);
this->Controls->Add(this->CalcButton);
this->Controls->Add(this->label2);
this->Controls->Add(this->Input2TextBox);
this->Controls->Add(this->label1);
this->Controls->Add(this->Input1TextBox);
this->Name = L"Form1";
this->Text = L"簡単計算プログラム";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void CalcButton_Click(System::Object^ sender, System::EventArgs^ e) {
//変数の宣言
int valueright;
int valueleft;
int valueanswer;
//値入力されたものを変数に代入
InputCheck(Input1TextBox->Text,valueright);
InputCheck(Input2TextBox->Text,valueleft);
//計算
valueanswer = valueright + valueleft;
//結果をテキストボックスに表示
AnswerTextBox->Text = valueanswer.ToString();
}
private: void InputCheck(System::String^ textValue,int % value)
{
if(int::TryParse(textValue,value) != true)
{
value = 0;
}
}
};
}