cscの作法 その84

# 概要
cscの作法、調べてみた。
練習問題やってみた。

# 練習問題

電卓を作れ。

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/afd16556-1b66-3ead-70bb-4d7ac5426373.png)

# サンプルコード

```


using System;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Drawing;

class Form1: Form {
	float i = 0;
	int j = 0;
	string k = "0";
	TextBox txt0;
	Form1() {
		Text = "cal";
		ClientSize = new Size(150, 150);

		txt0 = new TextBox();
		txt0.Location = new Point(10, 10);
		txt0.Size = new Size(120, 20);
		txt0.Text = "0";
		txt0.TextAlign = HorizontalAlignment.Right;
		Controls.Add(txt0);

		Button btn7 = new Button();
		btn7.Location = new Point(10, 30);
		btn7.Size = new Size(20, 20);
		btn7.Text = "7";
		btn7.Click += btn7_Click;
		Controls.Add(btn7);

		Button btn8 = new Button();
		btn8.Location = new Point(40, 30);
		btn8.Size = new Size(20, 20);
		btn8.Text = "8";
		btn8.Click += btn8_Click;
		Controls.Add(btn8);

		Button btn9 = new Button();
		btn9.Location = new Point(70, 30);
		btn9.Size = new Size(20, 20);
		btn9.Text = "9";
		btn9.Click += btn9_Click;
		Controls.Add(btn9);

		Button btna = new Button();
		btna.Location = new Point(100, 30);
		btna.Size = new Size(20, 20);
		btna.Text = "/";
		btna.Click += btna_Click;
		Controls.Add(btna);

		Button btn4 = new Button();
		btn4.Location = new Point(10, 60);
		btn4.Size = new Size(20, 20);
		btn4.Text = "4";
		btn4.Click += btn4_Click;
		Controls.Add(btn4);

		Button btn5 = new Button();
		btn5.Location = new Point(40, 60);
		btn5.Size = new Size(20, 20);
		btn5.Text = "5";
		btn5.Click += btn5_Click;
		Controls.Add(btn5);

		Button btn6 = new Button();
		btn6.Location = new Point(70, 60);
		btn6.Size = new Size(20, 20);
		btn6.Text = "6";
		btn6.Click += btn6_Click;
		Controls.Add(btn6);

		Button btnb = new Button();
		btnb.Location = new Point(100, 60);
		btnb.Size = new Size(20, 20);
		btnb.Text = "*";
		btnb.Click += btnb_Click;
		Controls.Add(btnb);

		Button btn1 = new Button();
		btn1.Location = new Point(10, 90);
		btn1.Size = new Size(20, 20);
		btn1.Text = "1";
		btn1.Click += btn1_Click;
		Controls.Add(btn1);

		Button btn2 = new Button();
		btn2.Location = new Point(40, 90);
		btn2.Size = new Size(20, 20);
		btn2.Text = "2";
		btn2.Click += btn2_Click;
		Controls.Add(btn2);

		Button btn3 = new Button();
		btn3.Location = new Point(70, 90);
		btn3.Size = new Size(20, 20);
		btn3.Text = "3";
		btn3.Click += btn3_Click;
		Controls.Add(btn3);

		Button btnc = new Button();
		btnc.Location = new Point(100, 90);
		btnc.Size = new Size(20, 20);
		btnc.Text = "-";
		btnc.Click += btnc_Click;
		Controls.Add(btnc);

		Button btn0 = new Button();
		btn0.Location = new Point(10, 120);
		btn0.Size = new Size(20, 20);
		btn0.Text = "0";
		btn0.Click += btn0_Click;
		Controls.Add(btn0);

		Button btnd = new Button();
		btnd.Location = new Point(40, 120);
		btnd.Size = new Size(20, 20);
		btnd.Text = ".";
		btnd.Click += btnd_Click;
		Controls.Add(btnd);

		Button btne = new Button();
		btne.Location = new Point(70, 120);
		btne.Size = new Size(20, 20);
		btne.Text = "+";
		btne.Click += btne_Click;
		Controls.Add(btne);

		Button btnf = new Button();
		btnf.Location = new Point(100, 120);
		btnf.Size = new Size(20, 20);
		btnf.Text = "=";
		btnf.Click += btnf_Click;
		Controls.Add(btnf);

	}
	void btn7_Click(object sender, System.EventArgs e) {
		if (k == "0") 
			k = "";
		k = k + "7";
		txt0.Text = k;
	}
	void btn8_Click(object sender, System.EventArgs e) {
		if (k == "0") 
			k = "";
		k = k + "8";
		txt0.Text = k;
	}
	void btn9_Click(object sender, System.EventArgs e) {
		if (k == "0") 
			k = "";
		k = k + "9";
		txt0.Text = k;
	}
	void btna_Click(object sender, System.EventArgs e) {
		i = float.Parse(k);
		j = 1;
		k = "0";
	}
	void btn4_Click(object sender, System.EventArgs e) {
		if (k == "0") 
			k = "";
		k = k + "4";
		txt0.Text = k;
	}
	void btn5_Click(object sender, System.EventArgs e) {
		if (k == "0") 
			k = "";
		k = k + "5";
		txt0.Text = k;
	}
	void btn6_Click(object sender, System.EventArgs e) {
		if (k == "0") 
			k = "";
		k = k + "6";
		txt0.Text = k;
	}
	void btnb_Click(object sender, System.EventArgs e) {
		i = float.Parse(k);
		j = 2;
		k = "0";
	}
	void btn1_Click(object sender, System.EventArgs e) {
		if (k == "0") 
			k = "";
		k = k + "1";
		txt0.Text = k;
	}
	void btn2_Click(object sender, System.EventArgs e) {
		if (k == "0") 
			k = "";
		k = k + "2";
		txt0.Text = k;
	}
	void btn3_Click(object sender, System.EventArgs e) {
		if (k == "0") 
			k = "";
		k = k + "3";
		txt0.Text = k;
	}
	void btnc_Click(object sender, System.EventArgs e) {
		i = float.Parse(k);
		j = 3;
		k = "0";
	}
	void btn0_Click(object sender, System.EventArgs e) {
		if (k == "0") 
			k = "";
		k = k + "0";
		txt0.Text = k;
	}
	void btnd_Click(object sender, System.EventArgs e) {
		k = k + ".";
		txt0.Text = k;
	}
	void btne_Click(object sender, System.EventArgs e) {
		i = float.Parse(k);
		j = 4;
		k = "0";
	}
	void btnf_Click(object sender, System.EventArgs e) {
		float v = float.Parse(k);
		switch (j)
		{
		case 0:
			v = 0;
		break;
		case 1:
			v = i / v;
		break;
		case 2:
			v = i * v;
		break;
		case 3:
			v = i - v;
		break;
		case 4:
			v = i + v;
		break;
		default:
		break;
		}
		txt0.Text = string.Format("{0}", v);
		k = "0";
	}
	[STAThread]
	public static void Main() {
		Application.Run(new Form1());
	}
}





```
以上。