All pastes #922326 Raw Edit

DenGulaFlummarFltan

public text v1 · immutable
#922326 ·published 2008-02-28 18:52 UTC
rendered paste body
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;



namespace WindowsApplication1

{

    public partial class Form1 : Form

    {

        decimal tal1 = 0;

        string op = "+";

        decimal tal2 = 0;

        decimal svar = 0;

        public Form1()

        {

            InitializeComponent();

        }



        private void textBox1_TextChanged(object sender, EventArgs e)

        {



        }



        private void button3_Click(object sender, EventArgs e)

        {

            textBox1.Text += "3";

        }



        private void Form1_Load(object sender, EventArgs e)

        {



        }



        private void button1_Click(object sender, EventArgs e)

        {

            textBox1.Text += "1";

        }



        private void button2_Click(object sender, EventArgs e)

        {

            textBox1.Text += "2";

        }



        private void button4_Click(object sender, EventArgs e)

        {

            textBox1.Text += "4";

        }



        private void button5_Click(object sender, EventArgs e)

        {

            textBox1.Text += "5";

        }



        private void button6_Click(object sender, EventArgs e)

        {

            textBox1.Text += "6";

        }



        private void button7_Click(object sender, EventArgs e)

        {

            textBox1.Text += "7";

        }



        private void button8_Click(object sender, EventArgs e)

        {

            textBox1.Text += "8";

        }



        private void button9_Click(object sender, EventArgs e)

        {

            textBox1.Text += "9";

        }



        private void plus_Click(object sender, EventArgs e)

        {

            decimal.TryParse(textBox1.Text, out tal1);

            textBox1.Text = " + ";

            op = "+";

            textBox1.Text = "";



        }



        private void ganger_Click(object sender, EventArgs e)

        {

            decimal.TryParse(textBox1.Text, out tal1);

            textBox1.Text = "*";

            textBox1.Text = "";

            op = "*";

        }



        private void minus_Click(object sender, EventArgs e)

        {

            decimal.TryParse(textBox1.Text, out tal1);

            textBox1.Text = "-";

            textBox1.Text = "";

            op = "-";

        }



        private void delat_Click(object sender, EventArgs e)

        {

            decimal.TryParse(textBox1.Text, out tal1);

            textBox1.Text = "/";

            textBox1.Text = "";

            op = "/";

        }



        private void upphojt_Click(object sender, EventArgs e)

        {

            decimal.TryParse(textBox1.Text, out tal1);

            textBox1.Text = "^";

            textBox1.Text = "";

            op = "^";

        }



        private void likamed_Click(object sender, EventArgs e)

        {

            decimal.TryParse(textBox1.Text, out tal2);

            textBox1.Text = " = ";



            textBox1.Text = "";



            if (op == "+")

            {

                svar = tal1 + tal2;

                textBox1.Text = Convert.ToString(svar);

            }

            else if (op == "/")

            {

                svar = tal1 / tal2;

                textBox1.Text = Convert.ToString(svar);

            }

            else if (op == "-")

            {

                svar = tal1 - tal2;

                textBox1.Text = Convert.ToString(svar);

            }

            else if (op == "*")

            {

                svar = tal1 * tal2;

                textBox1.Text = Convert.ToString(svar);

            }

            

                }



HÄNDELSEFÖRLOPP: 

Händelser

•	När man trycker på en sifferknapp så läggs siffran till i displayen.
•	När man trycker på en operatorknapp (+, -, *, /, ^) så gör vi om texten i displayen till ett tal och sparar i tal1. Vi sätter också variabeln op till rätt värde. Till slut tömmer vi displayen.
•	När man trycker på = så gör vi om texten i displayen till ett tal och sparar i tal2. Sedan räknas svaret ut på samma sätt som med den textbaserade miniräknaren och svaret sparas i tal1 och värdet på tal1 visas i displayen. Vi ändrar också operatorn till ’+’ och tal2 till 0 för säkerhets skull.