- El botón Calcular: Realiza la operación marcada en el control Operaciones.
- El botón Limpiar datos: debe borrar los TextBox
- El botón Salir: Sale del programa.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace semana77
{
public partial class Form1 : Form
{
public DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
}
private void Form1_Load_1(object sender, EventArgs e)
{
dt.Columns.Add(new DataColumn("Operacion"));
dt.Columns.Add(new DataColumn("Valor 1"));
dt.Columns.Add(new DataColumn("Valor 2"));
dt.Columns.Add(new DataColumn("Resultado"));
}
private void btn_clear_Click(object sender, EventArgs e)
{
text1.Text="";
text2.Text = "";
text_resulta.Text = "";
radio_suma.Checked = false;
radio_resta.Checked = false;
radio_producto.Checked = false;
radio_div.Checked = false;
radio_producto.Checked = false;
}
private void btn_close_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btn_calc_Click(object sender, EventArgs e)
{
if (radio_suma.Checked == true)
{
int re = int.Parse(text1.Text)+
int.Parse(text2.Text);
text_resulta.Text = re.ToString();
dt.Rows.Add(new string[]
{radio_suma.Text, text1.Text,text2.Text, text_resulta.Text = re.ToString() });
dataGridView1.DataSource
= dt;
}
if (radio_resta.Checked == true)
{
int r = int.Parse(text1.Text)
- int.Parse(text2.Text);
text_resulta.Text = r.ToString();
dt.Rows.Add(new string[] {
radio_resta.Text, text1.Text, text2.Text, text_resulta.Text });
dataGridView1.DataSource = dt;
}
if (radio_producto.Checked == true)
{
int p = int.Parse(text1.Text)
* int.Parse(text2.Text);
text_resulta.Text = p.ToString();
dt.Rows.Add(new string[] {
radio_producto.Text, text1.Text, text2.Text, text_resulta.Text });
dataGridView1.DataSource = dt;
}
if (radio_div.Checked == true)
{
float d = float.Parse(text1.Text)
/ float.Parse(text2.Text);
text_resulta.Text = d.ToString();
dt.Rows.Add(new string[] {
radio_div.Text, text1.Text, text2.Text, text_resulta.Text });
dataGridView1.DataSource = dt;
}
if (radio_potencia.Checked == true)
{
int n = int.Parse(text1.Text);
int n1 = int.Parse(text2.Text);
text_resulta.Text = Math.Pow(n,
n1).ToString();
dt.Rows.Add(new string[] {
radio_potencia.Text, text1.Text, text2.Text, text_resulta.Text});
dataGridView1.DataSource
= dt;
}
}
}
}
No hay comentarios:
Publicar un comentario