יש ליצור 4 תיבות טקסט בשמות:textBox1 - מקביל ל B / (A+B)
textBox2 - מקביל ל-A
textBox3 - מקביל ל-B
textBox5 - מקביל ל-A/B
ו-2 כפתורים בשמות:
button1 - שמאפס
button2 0 - כפתור "="
public Form1() { InitializeComponent(); textBox2.KeyPress += new KeyPressEventHandler(textBox2_KeyPress); textBox3.KeyPress += new KeyPressEventHandler(textBox3_KeyPress); } void textBox2_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) textBox3.Focus(); } void textBox3_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) calc(); } void calc() { textBox5.Text = Math.Round(Convert.ToDecimal(Convert.ToDecimal(textBox2.Text) / Convert.ToDecimal(textBox3.Text)), 1) + " to 1"; textBox1.Text = (Math.Round((Convert.ToDecimal(textBox3.Text) / (Convert.ToDecimal(textBox3.Text) + Convert.ToDecimal(textBox2.Text))) * 100, 1)).ToString() + "%"; } private void button2_Click(object sender, EventArgs e) { calc(); } private void button1_Click(object sender, EventArgs e) { textBox1.Text = textBox2.Text = textBox3.Text = textBox5.Text = ""; }
|
והקובץ: