Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Kalkulator
- {
- public partial class Form1 : Form
- {
- Double result = 0;
- String operation = "";
- bool isOperation = false;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void button_Click(object sender, EventArgs e)
- {
- if ((textBox1.Text == "0") || (isOperation))
- textBox1.Clear();
- isOperation = false;
- Button button = (Button)sender;
- if (button.Text == ".")
- {
- if (!textBox1.Text.Contains("."))
- textBox1.Text = textBox1.Text + button.Text;
- }
- else
- textBox1.Text = textBox1.Text + button.Text;
- }
- private void operator_Click(object sender, EventArgs e)
- {
- Button button = (Button)sender;
- if (result != 0)
- {
- button17.PerformClick();
- operation = button.Text;
- isOperation = true;
- }
- else
- {
- operation = button.Text;
- result = Double.Parse(textBox1.Text);
- isOperation = true;
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- textBox1.Text = "0";
- }
- private void button18_Click(object sender, EventArgs e)
- {
- textBox1.Text = "0";
- result = 0;
- }
- private void button17_Click(object sender, EventArgs e)
- {
- switch (operation)
- {
- case "+":
- textBox1.Text = (result + Double.Parse(textBox1.Text)).ToString();
- break;
- case "-":
- textBox1.Text = (result - Double.Parse(textBox1.Text)).ToString();
- break;
- case "*":
- textBox1.Text = (result * Double.Parse(textBox1.Text)).ToString();
- break;
- case "/":
- textBox1.Text = (result / Double.Parse(textBox1.Text)).ToString();
- break;
- default:
- break;
- }
- result = Double.Parse(textBox1.Text);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment