У меня есть калькулятор, но его необходимо изменить
У меня есть calciulator. он отлично работает, введите 10-5 в текстовое поле1 и результат, показанный в текстовом поле2. но я хочу рассчитать больше. пример 8-5 * 3-1. или 7-2 + 3 и так далее.
как это будет? вот мой код
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
float ricxvi1, pasuxi;
int datvla;
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
textBox1.Clear();
textBox1.Text = textBox1.Text + 7;
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox1.Text = textBox1.Text + 0;
textBox2.Clear();
textBox2.Text = textBox2.Text + 0;
datvla = 0;
}
private void button6_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
textBox1.Clear();
textBox1.Text = textBox1.Text + 4;
}
private void button17_Click(object sender, EventArgs e)
{
ricxvi1 = ricxvi1 = float.Parse(textBox1.Text);
datvla = 1;
textBox1.Text += "-";
}
private void button10_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
textBox1.Clear();
textBox1.Text = textBox1.Text + 1;
}
private void button11_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
textBox1.Clear();
textBox1.Text = textBox1.Text + 2;
}
private void button12_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
textBox1.Clear();
textBox1.Text = textBox1.Text + 3;
}
private void mimateba_Click_1(object sender, EventArgs e)
{
ricxvi1 = float.Parse(textBox1.Text);
datvla = 2;
textBox1.Text += "+";
}
private void button7_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
textBox1.Clear();
textBox1.Text = textBox1.Text + 5;
}
private void button8_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
textBox1.Clear();
textBox1.Text = textBox1.Text + 6;
}
private void button5_Click(object sender, EventArgs e)
{
ricxvi1 = float.Parse(textBox1.Text);
datvla = 3;
textBox1.Text += "*";
}
private void button3_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
textBox1.Clear();
textBox1.Text = textBox1.Text + 8;
}
private void button4_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
textBox1.Clear();
textBox1.Text = textBox1.Text + 9;
}
private void button9_Click(object sender, EventArgs e)
{
ricxvi1 = float.Parse(textBox1.Text);
datvla = 4;
textBox1.Text += "/";
}
private void button14_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 0;
}
private void button16_Click_1(object sender, EventArgs e)
{
switch (datvla)
{
case 1:
pasuxi = ricxvi1 - float.Parse(textBox1.Text.Substring(textBox1.Text.Length - 1));
textBox2.Text = pasuxi.ToString();
break;
case 2:
pasuxi = ricxvi1 + float.Parse(textBox1.Text.Substring(textBox1.Text.Length - 1));
textBox2.Text = pasuxi.ToString();
break;
case 3:
pasuxi = ricxvi1 * float.Parse(textBox1.Text.Substring(textBox1.Text.Length - 1));
textBox2.Text = pasuxi.ToString();
break;
case 4:
pasuxi = ricxvi1/float.Parse(textBox1.Text.Substring(textBox1.Text.Length - 1));
textBox2.Text = pasuxi.ToString();
break;
default:
break;
}
}
private void button15_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
textBox1.Clear();
textBox1.Text = textBox1.Text + ".";
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
Пожалуйста, внимательно прочитайте [как задавать вопросы на SO-сайте] (http://stackoverflow.com/help/how-to-ask). Основная идея - ** вы должны предоставить свой код и описать свою проблему ** (неожиданные результаты или ошибки). В настоящее время этот вопрос только описывает вашу задачу, но ничего не сообщает о вашей конкретной проблеме и не показывает никакого кода, с которым у вас проблемы. –
Вы ищете что-то вроде этого? http://stackoverflow.com/questions/21950093/string-calculator – Marius
нет есть другие проблемы. string преобразовать в int для вычисления результата. – refreshg