Nothing Special   »   [go: up one dir, main page]

Calcula Dora Basic A

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Aleix Collado Serrano

FORM1.CS
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 CalculadoraBasica
{
public partial class Form1 : Form

{
int operation = 0;
public Form1()
{
InitializeComponent();
}

private void label1_Click(object sender, EventArgs e)


{

private void label3_Click(object sender, EventArgs e)


{

private void textBox3_TextChanged(object sender, EventArgs e)


{

private void Form1_Load(object sender, EventArgs e)


{

private void button4_Click(object sender, EventArgs e)


{
Loperation.Text = "X";
operation = 1;
}

private void button2_Click(object sender, EventArgs e)


{
Loperation.Text = "/";
operation = 2;
}

private void button3_Click(object sender, EventArgs e)


{
Aleix Collado Serrano

Loperation.Text = "+";
operation = 3;
}

private void button1_Click(object sender, EventArgs e)


{
Loperation.Text = "-";
operation = 4;
}
private void button6_Click(object sender, EventArgs e)
{
Loperation.Text = "MOD";
operation = 5;
}
private void button5_Click(object sender, EventArgs e)
{
switch (operation)

case 1:
tresultado.Text = Convert.ToString(int.Parse(tnombre1.Text) *
int.Parse(tnombre2.Text));
break;
case 2:
tresultado.Text = Convert.ToString(int.Parse(tnombre1.Text) /
int.Parse(tnombre2.Text));
break;
case 3:
tresultado.Text = Convert.ToString(int.Parse(tnombre1.Text) +
int.Parse(tnombre2.Text));
break;
case 4:
tresultado.Text = Convert.ToString(int.Parse(tnombre1.Text) -
int.Parse(tnombre2.Text));
break;
case 5:
tresultado.Text = Convert.ToString(int.Parse(tnombre1.Text) %
int.Parse(tnombre2.Text));
break;
default:
MessageBox.Show("Ha de seleccionar una operació abans.");
break;

private void tnombre1_TextChanged(object sender, EventArgs e)


{

ComprovarCampo.check((System.Windows.Forms.TextBox)sender, 48, 57);


}

private void tnombre2_TextChanged(object sender, EventArgs e)


{
Aleix Collado Serrano

ComprovarCampo.check((System.Windows.Forms.TextBox)sender, 48, 57);

}
}

ComprovarCampo.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CalculadoraBasica
{
class ComprovarCampo
{

public static Boolean check(TextBox textbx, int asciiminvalue, int


asciimaxvalue)
{
Boolean res = false;
TextBox textbox = textbx;
int tmp = textbox.SelectionStart - 1;
byte[] ascii = Encoding.ASCII.GetBytes(textbox.Text);
for (int i = 0; i < ascii.Length; i++)
{
if (ascii[i] < asciiminvalue || ascii[i] > asciimaxvalue)
{
textbox.Text = textbox.Text.Remove(tmp, 1);
textbox.SelectionStart = tmp;
res = true;
}

}
return res;
}
}
}
Aleix Collado Serrano

Capturas de pantalla

You might also like