dunque, ho realizzato un programmino (molto stupido) che fa da calcolatrice.
ora, funziona egregiamente, ma vorrei aggiungergli un paio di cose.
intanto il sorgente:
codice:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Calculator
{
public partial class Form1 : Form
{
string operando;
public Form1()
{
InitializeComponent();
textBox2.Text = "0";
}
private void button8_Click(object sender, EventArgs e)
{
int operando1 = Convert.ToInt32(textBox1.Text);
int operando2 = Convert.ToInt32(textBox2.Text);
int risultato = operando1 + operando2;
string risultato2 = Convert.ToString(risultato);
textBox2.Text = risultato2;
textBox1.Text = "0";
operando = "0";
}
private void button1_Click(object sender, EventArgs e)
{
operando = operando + "1";
textBox1.Text = operando;
}
private void button5_Click(object sender, EventArgs e)
{
operando = operando + "2";
textBox1.Text = operando;
}
private void button3_Click(object sender, EventArgs e)
{
operando = operando + "3";
textBox1.Text = operando;
}
private void button6_Click(object sender, EventArgs e)
{
operando = operando + "4";
textBox1.Text = operando;
}
private void button2_Click(object sender, EventArgs e)
{
operando = operando + "5";
textBox1.Text = operando;
}
private void button12_Click(object sender, EventArgs e)
{
operando = operando + "6";
textBox1.Text = operando;
}
private void button11_Click(object sender, EventArgs e)
{
operando = operando + "7";
textBox1.Text = operando;
}
private void button10_Click(object sender, EventArgs e)
{
operando = operando + "8";
textBox1.Text = operando;
}
private void button9_Click(object sender, EventArgs e)
{
operando = operando + "9";
textBox1.Text = operando;
}
private void button7_Click(object sender, EventArgs e)
{
int operando1 = Convert.ToInt32(textBox1.Text);
int operando2 = Convert.ToInt32(textBox2.Text);
int risultato = operando2 - operando1;
string risultato2 = Convert.ToString(risultato);
textBox2.Text = risultato2;
textBox1.Text = "0";
operando = "0";
}
}
}
ecco cosa vorrei aggiungere:
1) il programma funziona correttamente quando si premono con il mouse i pulsanti dei numeri e delle operazioni, io vorrei che funzionasse anche premendo i numeri sulla tastiera..........
2) dato che devo riazzerare addendo ogni qual volta viene visualizzata un'operazione, ho messo come istruzione
operando = "0";
solo che essendo una stringa a cui vengono concatenati i nuovi numeri che uno seleziona, se io premo 5 6 e 7 viene visualizzato
0567
che non sta molto bene.......
come faccio a togliere lo 0 davanti?
ho già provato con
addendo="";
ma il risultato è lo stesso.......