게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
c# 윈도우폼 계산기 질문이여 ㅜㅜ
게시물ID : programmer_21941짧은주소 복사하기
작성자 : 010705
추천 : 0
조회수 : 1288회
댓글수 : 1개
등록시간 : 2017/12/31 18:09:13
namespace ha
{
    public partial class Form1 : Form
    {
      
        public Form1()
        {
            InitializeComponent();
        }
       
        double num1 = 0;
        string oper = "";
        string secondNumber = "";
        double minus = 0;
        bool s;
        double firstZero = 0;
        double result = 0;
        private void Form1_Load(object sender, EventArgs e)
        {
         
        }
    
        private void Number1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0" || s == true )
            {
                textBox1.Text = "1";
                s = false;
                secondNumber = textBox1.Text;
               
            }
            else
            {
                textBox1.Text = textBox1.Text + "1";
                secondNumber = textBox1.Text ;
            }
        
        }
        private void Number2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0" || s == true)
            {
                textBox1.Text = "2";
                s = false;
                secondNumber = textBox1.Text;
            }
            else
            {
                textBox1.Text = textBox1.Text + "2";
                secondNumber = textBox1.Text;
            }
        }
        private void Number3_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0" || s == true)
            {
                textBox1.Text = "3";
                s = false;
                secondNumber = textBox1.Text;
            }
            else
            {
                textBox1.Text = textBox1.Text + "3";
                secondNumber = textBox1.Text;
            }
        }
        private void Number4_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0" || s == true)
            {
                textBox1.Text = "4";
                s = false;
                secondNumber = textBox1.Text;
            }
            else
            {
                textBox1.Text = textBox1.Text + "4";
                secondNumber = textBox1.Text;
            }
        }
        private void Number5_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0" || s == true)
            {
                textBox1.Text = "5";
                s = false;
                secondNumber = textBox1.Text;
            }
            else
            {
                textBox1.Text = textBox1.Text + "5";
                secondNumber = textBox1.Text;
            }
        }
        private void Number6_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0" || s == true)
            {
                textBox1.Text = "6";
                s = false;
                secondNumber = textBox1.Text;
            }
            else
            {
                textBox1.Text = textBox1.Text + "6";
                secondNumber = textBox1.Text;
            }
        }
        private void Number7_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0" || s == true)
            {
                textBox1.Text = "7";
                s = false;
                secondNumber = textBox1.Text;
            }
            else
            {
                textBox1.Text = textBox1.Text + "7";
                secondNumber = textBox1.Text;
            }
        }
        private void Number8_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0" || s == true)
            {
                textBox1.Text = "8";
                s = false;
                secondNumber = textBox1.Text;
            }
            else
            {
                textBox1.Text = textBox1.Text + "8";
                secondNumber = textBox1.Text;
            }
        }
        private void Number9_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0" || s == true)
            {
                textBox1.Text = "9";
                s = false;
                secondNumber = textBox1.Text;
            }
            else
            {
                textBox1.Text = textBox1.Text + "9";
                secondNumber = textBox1.Text;
            }
        }
        private void Number10_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0" || s == true)
            {
                textBox1.Text = "0";
                s = false;
                secondNumber = textBox1.Text;
            }
            else
            {
                textBox1.Text = textBox1.Text + "0";
                secondNumber = textBox1.Text;
            }
        }
        private void Plus_Click(object sender, EventArgs e)
        {
            num1 = Double.Parse(textBox1.Text);
            textBox2.Text += textBox1.Text+ "+" ;
            oper = "+";
            s = true;
        }
        private void Minus_Click(object sender, EventArgs e)
        {
            num1 = Double.Parse(textBox1.Text);
            textBox2.Text = textBox1.Text + "-";
            oper = "-";
            s = true;
        }
        private void Multiply_Click(object sender, EventArgs e)
        {
            num1 = Double.Parse(textBox1.Text);
            textBox2.Text = textBox1.Text + "*";
            oper = "*";
            s = true;
          
        }
        private void divide_Click(object sender, EventArgs e)
        {
            num1 = Double.Parse(textBox1.Text);
            textBox2.Text = textBox1.Text + "/";
            oper = "/";
            s = true;
        }
        private void Delete_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text.Remove(textBox1.TextLength - 1);
            if (textBox1.TextLength == 0)
            {
                textBox1.Text = "0";
            }
        }
        private void CLear_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            num1 = 0;
            oper = "";
            s = false;
        }
        private void Calculator_Click(object sender, EventArgs e)
        {
             result = double.Parse(textBox1.Text);
       
            if(oper == "+")
            {
                textBox1.Text = (+num1 + result).ToString();
            }
            else if (oper == "-")
            {
                textBox1.Text = (num1 - result).ToString();
            }
            else if (oper == "*")
            {
                textBox1.Text = (num1 * result).ToString();
            }
            else if (oper == "/")
            {
                textBox1.Text = (num1 / result).ToString();
            }
            textBox2.Text = "";
            richTextBox1.Text += num1 + oper+ secondNumber + "="+textBox1.Text+"\r\n";
        }
        private void muipl_Click(object sender, EventArgs e)
        {
             minus = double.Parse(textBox1.Text);
            textBox1.Text = (-minus).ToString();
        }
        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            richTextBox1.SelectionStart = richTextBox1.Text.Length;
            richTextBox1.ScrollToCaret();
        }
  
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           
        }
       
    }
   
}
 
여기서  텍스트박스에 무조건 0이 들어가서 0과 더해지거나 뺄수 있게 하고 싶은데 어떻게 해야할지 몰라서 질문드립니다 ㅜ
왜냐하면 초기값에 -라는 문자열을 넣으면 문자로 인식해서 파싱 할때 오류가 나서 음수값이 나오지가 않아여 ㅜㅜ
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호