반응형
내 나름 최종본이다.
그리고 그냥 전부 포함하겠다.
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 Calc
{
public partial class Calc : Form
{
public Calc()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void Calc_Click(object sender, EventArgs e)
{
}
int number1 = 0;
int number2 = 0;
private void sum_numbers_Click(object sender, EventArgs e) //+
{
if (int.TryParse(input2.Text, out number2) == false)
{
MessageBox.Show("숫자를 넣어주세요.");
input2.Focus();
return;
//이 이벤트 탈출
//int형이면 return0;
}
if (String.IsNullOrWhiteSpace(input2.Text))
{
MessageBox.Show("숫자를 넣어주세요.");
input2.Focus();
return;
}
number1 = Convert.ToInt32(input1.Text);
number2 = Convert.ToInt32(input2.Text);
//Convert => system에 포함. 맨위에 using System이 있기에 사용 가능함.
//int는 그냥 32임 사이즈가.
//Convert 사용법 => Convert.To바꾸고싶은자료형(바꿀대상)
int sum = number1 + number2;
resultbox.Text = Convert.ToString(sum);
}
private void minus_numbers_Click(object sender, EventArgs e)// -
{
if (int.TryParse(input1.Text, out number1) == false)
{
MessageBox.Show("숫자를 넣어주세요.");
input1.Focus();
return;
}
if (int.TryParse(input2.Text, out number2)==false )
{
MessageBox.Show("숫자를 넣어주세요.");
input2.Focus();
return;
}
number1 = Convert.ToInt32(input1.Text);
number2 = Convert.ToInt32(input2.Text);
int minus = number1 - number2;
resultbox.Text = Convert.ToString(minus);
}
private void x_numbers_Click(object sender, EventArgs e) // *
{
if (int.TryParse(input1.Text, out number1) == false)
{
MessageBox.Show("숫자를 넣어주세요.");
input1.Focus();
return;
}
if (int.TryParse(input2.Text, out number2) == false)
{
MessageBox.Show("숫자를 넣어주세요.");
input2.Focus();
return;
}
number1 = Convert.ToInt32(input1.Text);
number2 = Convert.ToInt32(input2.Text);
int multi = number1 * number2;
resultbox.Text = Convert.ToString(multi);
}
private void div_numbers_Click(object sender, EventArgs e)// /
{
if (int.TryParse(input1.Text, out number1) == false)
{
MessageBox.Show("숫자를 넣어주세요.");
input1.Focus();
return;
}
if (int.TryParse(input2.Text, out number2) == false)
{
MessageBox.Show("숫자를 넣어주세요.");
input2.Focus();
return;
}
number1 = Convert.ToInt32(input1.Text);
number2 = Convert.ToInt32(input2.Text);
int div = number1 / number2;
resultbox.Text = Convert.ToString(div);
}
private void Calc_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (int.TryParse(input1.Text, out number1) == false)
{
MessageBox.Show("숫자를 넣어주세요.");
input1.Focus();
return;
}
if (int.TryParse(input2.Text, out number2) == false)
{
MessageBox.Show("숫자를 넣어주세요.");
input2.Focus();
return;
}
number1 = Convert.ToInt32(input1.Text);
number2 = Convert.ToInt32(input2.Text);
int div = number1 % number2;
resultbox.Text = Convert.ToString(div);
}
private void label2_Click(object sender, EventArgs e)
{
}
private void no1_Click(object sender, EventArgs e)
{
input1.Text = input1.Text + "1";
}
private void splitter1_SplitterMoved(object sender, SplitterEventArgs e)
{
}
private void no2_Click(object sender, EventArgs e)
{
input1.Text = input1.Text + "2";
}
private void no3_Click(object sender, EventArgs e)
{
input1.Text = input1.Text + "3";
}
private void no4_Click(object sender, EventArgs e)
{
input1.Text = input1.Text + "4";
}
private void no5_Click(object sender, EventArgs e)
{
input1.Text = input1.Text + "5";
}
private void no6_Click(object sender, EventArgs e)
{
input1.Text = input1.Text + "6";
}
private void no7_Click(object sender, EventArgs e)
{
input1.Text = input1.Text + "7";
}
private void no8_Click(object sender, EventArgs e)
{
input1.Text = input1.Text + "8";
}
private void no9_Click(object sender, EventArgs e)
{
input1.Text = input1.Text + "9";
}
private void button2_Click(object sender, EventArgs e)
{
input1.Text = input1.Text + "0";
}
private void no11_Click(object sender, EventArgs e)
{
input2.Text = input2.Text + "1";
}
private void no22_Click(object sender, EventArgs e)
{
input2.Text = input2.Text + "2";
}
private void no33_Click(object sender, EventArgs e)
{
input2.Text = input2.Text + "3";
}
private void no44_Click(object sender, EventArgs e)
{
input2.Text = input2.Text + "4";
}
private void no55_Click(object sender, EventArgs e)
{
input2.Text = input2.Text + "5";
}
private void no66_Click(object sender, EventArgs e)
{
input2.Text = input2.Text + "6";
}
private void no77_Click(object sender, EventArgs e)
{
input2.Text = input2.Text + "7";
}
private void no88_Click(object sender, EventArgs e)
{
input2.Text = input2.Text + "8";
}
private void no99_Click(object sender, EventArgs e)
{
input2.Text = input2.Text + "9";
}
private void button3_Click(object sender, EventArgs e)
{
input2.Text = input2.Text + "0";
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
int set_neg = 0;
if(set_neg != 0)
{
set_neg = 1;
}
else
{
set_neg = 0;
}
}
}
}
제일 마지막에 있는 checkBox1_이거는 미완이니까 그냥 무시해도 될 것 같다.
반응형
'코오딩 > _C#' 카테고리의 다른 글
C# 계산기시도하기 - 3 (0) | 2021.02.25 |
---|---|
C# 계산기시도하기-2 (0) | 2021.02.24 |
C# 계산기 시도하기 - 1 (0) | 2021.02.21 |
C# 기초 / Hello, world 뜯기 (0) | 2021.02.19 |