Saludo Gianni11,veo que dite el hilo por terminado pero tuve el atrevimiento de descargar el codigo para hacerles algunas modificaciones y trabaja a la perfecion, verificalo.
using System; using System.Windows.Forms;namespaceWindowsFormsApplication21
{
publicpartialclassForm1:Form{ float resultado = 0; //string error1 = "+"; bool suma, resta, multi, div; public Form14() { InitializeComponent(); } private void btnmas_Click(object sender, EventArgs e) { float x; if (!float.TryParse(textBox1.Text, out x)) { MessageBox.Show("Valor no permitido"); } else { textBox1.Text = string.Empty; resultado = resultado + x; suma = true; textBox1.Focus(); } } private void btnmenos_Click(object sender, EventArgs e) { float x; if (!float.TryParse(textBox1.Text, out x)) { MessageBox.Show("Valor no permitido"); } else { resultado = resultado + x; resta = true; textBox1.Focus(); textBox1.Text = string.Empty; } } private void btnpor_Click(object sender, EventArgs e) { float x; if (!float.TryParse(textBox1.Text, out x)) { MessageBox.Show("Valor no permitido"); } else { resultado = resultado + x; multi = true; textBox1.Focus(); textBox1.Text = string.Empty; } } private void btndividio_Click(object sender, EventArgs e) { float x; if (!float.TryParse(textBox1.Text, out x)) { MessageBox.Show("Valor no permitido"); } else { resultado = resultado + x; div = true; textBox1.Focus(); textBox1.Text = string.Empty; } } private void btnigual_Click(object sender, EventArgs e) { if (suma) { resultado += Convert.ToSingle(textBox1.Text); } if (resta) { resultado -= Convert.ToSingle(textBox1.Text); } if (multi) { resultado *= Convert.ToSingle(textBox1.Text); } if (div) { resultado /= Convert.ToSingle(textBox1.Text); } textBox1.Text = resultado.ToString(); suma = false; resta = false; multi = false; div = false; resultado = 0; } private void btnborrar_Click(object sender, EventArgs e) { textBox1.Clear(); textBox1.Focus(); } private void textBox1_TextChanged(object sender, EventArgs e) { } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)&& e.KeyChar != ',') { e.Handled = true; } if (e.KeyChar == ',' && (sender as TextBox).Text.IndexOf(',') > -1) { e.Handled = true; } } } }
Angel R. Jimenez G. Software Development Santo Domingo Republica Dominicana Blog | ![]() |