Winform--계산기

25218 단어 WinForm
namespace    2._0

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private bool Isok = true;//           ,          (               )

        private string Biaodashi; //           (    )

        private decimal Sum;//         (    )

        private string Preyunsuanfu;//        

        private decimal d2;//          





        private void button32_Click(object sender, EventArgs e)//      

        {

            Button btn = (Button) sender; //sender       ,         

            if (Isok) //                  

            {

                textBox2.Text = btn.Text; //                   

                Isok = false;// Isok  false   :          ,        ,     else

                d2 = decimal.Parse(textBox2.Text);

            }

            else

            {

                textBox2.Text = textBox2.Text + btn.Text;//

            }

        }



        private void button36_Click(object sender, EventArgs e)//0  

        {

            Button btn = (Button)sender; //sender       ,         

            if (Isok) //                  

            {

                textBox2.Text = btn.Text; //                   

                

            }

            else

            {

                textBox2.Text = textBox2.Text + btn.Text;//

            }

        }



        private void button44_Click(object sender, EventArgs e)//   

        {

            Button btn = (Button)sender;//sender       ,         

            string yunsuanfu = btn.Text; //          yunsuanfu;

            if (Preyunsuanfu == null)

            {

                Biaodashi =  textBox2.Text; 

                Sum = decimal.Parse(textBox2.Text);

            }

            else

            {

                if (!Isok) //         ,           .       .

                {   // !Isok             ,           .

                    if (Preyunsuanfu == "+") //           

                    {

                        Sum = Sum + decimal.Parse(textBox2.Text);//                    

                    }

                    if (Preyunsuanfu == "-")

                    {

                        Sum = Sum - decimal.Parse(textBox2.Text);

                    }

                    if (Preyunsuanfu == "*")

                    {

                        Sum = Sum * decimal.Parse(textBox2.Text);

                    }

                    if (Preyunsuanfu == "/")

                    {

                        Sum = Sum / decimal.Parse(textBox2.Text);

                    }

                    if (Preyunsuanfu == "%")

                    {

                        Sum = Sum % decimal.Parse(textBox2.Text);

                    }

                    Biaodashi = Biaodashi + Preyunsuanfu + textBox2.Text;//                         +         +      

                    textBox2.Text = Sum.ToString(); //         

                }

            

            }

            textBox1.Text = Biaodashi + yunsuanfu;//            +        

            Preyunsuanfu = yunsuanfu;// yunsuanfu                ;

            Isok = true; //  Isok ture,                    



        }



        private void button8_Click(object sender, EventArgs e) //   

        {   //       

            textBox1.Text = "";

            textBox2.Text = "0";

            Isok = true;

            Preyunsuanfu = null;

            Sum = 0;

            Biaodashi = "";

            d2 = 0;

        }



        private void button6_Click(object sender, EventArgs e)//   

        {

            if (!Isok) //                   

            {

                if (textBox2.Text.Length == 1)//           1

                {

                    textBox2.Text = "0"; //        0

                    Isok = true;//     0,  Isok  true.    0     ,         。

                }

                else

                {

                    textBox2.Text = textBox2.Text.Substring(0, textBox2.Text.Length - 1);

                }

            }

           

        }



        private void button28_Click(object sender, EventArgs e) //   

        { 

            if(!textBox2.Text.Contains("."))//               

            {

                textBox2.Text = textBox2.Text + ".";

                Isok = false;//       

            }

        }

      // private bool d3 = true;//        

        private void button30_Click(object sender, EventArgs e) //      

       {

           Button btn = (Button)sender;

            

            textBox1.Text = ""; //      

           

            //       

            if (Preyunsuanfu == "+") //           

            {

                Sum = Sum + decimal.Parse(textBox2.Text);//                    

            }

            if (Preyunsuanfu == "-")

            {

                Sum = Sum - decimal.Parse(textBox2.Text);

            }

            if (Preyunsuanfu == "*")

            {

                Sum = Sum * decimal.Parse(textBox2.Text);

            }

            if (Preyunsuanfu == "/")

            {

                Sum = Sum / decimal.Parse(textBox2.Text);

            }

            if (Preyunsuanfu == "%")

            {

                Sum = Sum % decimal.Parse(textBox2.Text);

            }

          

            textBox2.Text = Sum.ToString();//           



            

            //     

            Isok = true;

            Biaodashi = "";

            Preyunsuanfu = null;

          

            Sum = d2+decimal.Parse(textBox2.Text);



            //             

           

            

        }



        private void button9_Click(object sender, EventArgs e)  //   

        {

            if (!Isok) //

            {

                if (decimal.Parse(textBox2.Text) > 0)

                {

                    textBox2.Text = "-" + textBox2.Text;//          

                }

                else

                {

                    textBox2.Text = textBox2.Text.Substring(1);//           

                }

            }

        }

        private string m;

        private void button4_Click(object sender, EventArgs e) //M+   textbox2     M+  

        {

            if (textBox2.Text == "0")

            {



            }

            else

            {

                textBox3.Text = "M";

            }

            m = textBox2.Text;

        }



        private void button2_Click(object sender, EventArgs e)//MR   MR  M+    ;

        {

            textBox2.Text = m;

        }



        private void button5_Click(object sender, EventArgs e)//M-   M+           

        {

            if(!Isok)//         

            {

            Sum=decimal.Parse(m)-decimal.Parse(textBox2.Text);

            textBox2.Text = Sum.ToString();

            }

        }





        private double ss;

        private void button10_Click(object sender, EventArgs e)//  

        {

           ss = Math.Sqrt(double.Parse(textBox2.Text));

           textBox1.Text = "sqrt" + "(" + textBox2.Text + ")";

           textBox2.Text = ss.ToString();

           Isok = true;

        }



        private void textBox2_TextChanged(object sender, EventArgs e)

        {



        }



        private void textBox1_TextChanged(object sender, EventArgs e)

        {



        }

        private double fenshu;

        private void button41_Click(object sender, EventArgs e)//    

        {

            fenshu = 1 / double.Parse(textBox2.Text);  

            textBox1.Text = "reciproc" + "("+textBox2.Text+")";//      

            textBox2.Text = fenshu.ToString();//      

          

        }



        private void button7_Click(object sender, EventArgs e)//CE  C     

        {

            //       

            textBox1.Text = "";

            textBox2.Text = "0";

            Isok = true;

            Preyunsuanfu = null;

            Sum = 0;

            Biaodashi = "";

        }



        private void button1_Click(object sender, EventArgs e) //MC   M+    

        {

            textBox3.Text = "";

            m = "0";

        }



    }

}

좋은 웹페이지 즐겨찾기