Dziękuję za odpowiedź!
To co napisałeś wystarczyło żebym znalazł problem natomiast teraz mam problem z działaniami matematyczni. Po kliknięciu przycisku dodawania i wybraniu kolejnych cyfr w polu tekstowym zaczynają się wyświetlać pojedyncze cyfry, a nie tak jak wcześniej ich ciąg i dodatkowo operacja dodawania nie działa tzn. po kliknięciu równa się nic się nie dzieje.
Wklejam cały mój kod.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Double value = 0;
String operation = ""; //variable - type String name operation
bool operation_pressed = false; // sets variable bool as false
public Form1()
{
InitializeComponent();
}
private void button_Click(object sender, EventArgs e) ///method - double click on a button in forms generates this line of code
///which is responsible for what happens after pressing the button
{
// result.Text = result.Text + "1"; ///this line creates Text result in TextBox named "result"
///assigned value result.Text + "1" generates number 1 after every press of the button 1
if ((result.Text == "0")||(operation_pressed)) ///instruction if - if in TextBox is only 0 leave it
result.Clear(); ///if not remove 0 from the beginning
Button b = (Button)sender; ///Button represents a Button in forms and "b" is assigned as variable.
///(Button)sender -
result.Text = result.Text + b.Text; ///result in TextBox is an assigned number of button
label1.Text = result.Text; //result in Label1 the same like in the result TextBox
}
private void button5_Click(object sender, EventArgs e)
{
result.Text = "0"; //button5 is a CE button - after pressing that button it clears TextBox
label1.Text = result.Text;
}
private void operator_click(object sender, EventArgs e)
{
Button b = (Button)sender;
operation = b.Text;
value = Double.Parse(result.Text);
operation_pressed = true; //after pressing operation button (+,-,*,/, etc.) it prevents from clearing TextBox
}
private void button18_Click(object sender, EventArgs e)
{
Double value = 0;
switch (operation)
{
case "+":
result.Text = (value + Double.Parse(result.Text)).ToString();
break;
case "-":
result.Text = (value - Double.Parse(result.Text)).ToString();
break;
case "*":
result.Text = (value * Double.Parse(result.Text)).ToString();
break;
case "/":
result.Text = (value / Double.Parse(result.Text)).ToString();
break;
///case "^":
///result.Text = (value ^ Double.Parse(result.Text)).ToString();
///break;
///case "sqrt":
///result.Text = (value sqrt Double.Parse(result.Text)).ToString();
///break;
default:
break;
}//switch end
operation_pressed = false;
}
private void button10_Click(object sender, EventArgs e)
{
result.Clear();
value = 0;
}
}
}