|
お二方ありがとうございます ほんとにプログラム初心者で右も左もわからないので感謝です
今はこんな状態です
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;
namespace WindowsFormsApplication2 { public partial class Form1: Form {
public Form1() { InitializeComponent(); }
bool isFirst = true; decimal x = 0; private void buttonNumber_Click(object sender, EventArgs e) { if (key != Operator.undefined && isFirst) { x = Convert.ToDecimal(textBox1.Text); textBox1.Text = ""; isFirst = false; }
String text = textBox1.Text + ((Button)sender).Text;
decimal d = Convert.ToDecimal(text);
String text2 = d.ToString();
textBox1.Text = text2; }
private void buttonClear_Click(object sender, EventArgs e) { textBox1.Text = ""; }
private void buttonDot_Click(object sender, EventArgs e) { if (textBox1.Text.IndexOf(".") >= 0) { return; }
textBox1.Text = textBox1.Text + "."; }
enum Operator { undefined, add, sub, mul, dvi };
Operator key = Operator.undefined;
private void buttonAdd_Click(object sender, EventArgs e) { key= Operator.add; isFirst = true; }
private void buttonSub_Click(object sender, EventArgs e) { key=Operator.sub; isFirst = true; }
private void buttonMul_Click(object sender, EventArgs e) { key= Operator.mul; isFirst = true; }
private void buttonDvi_Click(object sender, EventArgs e) { key= Operator.dvi; isFirst = true; }
private void buttonResult_Click(object sender, EventArgs e) { decimal y = Convert.ToDecimal(textBox1.Text); decimal results = 0; switch (key) { case Operator.add: results = x + y;
break;
case Operator.sub: results = x - y; break;
case Operator.mul: results = x * y; break;
case Operator.dvi: results = x / y; break;
}
textBox1.Text = results.ToString();
} } }
|