using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Winform_01 {
public partial class Calc : Form {
//계산기
public Calc() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
string name1 = ((Button)sender).Name;
string name2 = ((Button)sender).Text;
int res = 0;
if (textBox1.Text == string.Empty) {
textBox1.Focus();
return;
}
if (textBox2.Text == string.Empty) {
textBox2.Focus();
return;
}
if (textBox1.Text == string.Empty&& textBox2.Text == string.Empty) {
textBox1.Focus();
return;
}
switch (name1) {
case "button1":
res = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);
textBox3.Text = res.ToString();
break;
case "button2":
res = int.Parse(textBox1.Text) - int.Parse(textBox2.Text);
textBox3.Text = res.ToString();
break;
case "button3":
res = int.Parse(textBox1.Text) * int.Parse(textBox2.Text);
textBox3.Text = res.ToString();
break;
case "button4":
if (int.Parse(textBox2.Text) == 0) {
MessageBox.Show("0 으로 나눌수는 없습니다.");
}
else {
res = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
textBox3.Text = res.ToString();
}
break;
case "button5":
textBox1.Text = string.Empty;
textBox2.Text = string.Empty;
textBox3.Text = string.Empty;
break;
}
}
}
}
'C# > C# 연습' 카테고리의 다른 글
WinForm : 로그인 (0) | 2022.12.25 |
---|---|
WinForm : 퀴즈 게임 (0) | 2022.12.24 |
Class : Student manage (0) | 2022.12.20 |
Class : Student Score (0) | 2022.12.18 |
Class : Car Manager (0) | 2022.12.18 |