1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | namespace _103303067_0504_01 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { double no1, no2, sum ; no1 = Convert.ToInt32(textBox1.Text); no2 = Convert.ToInt32(textBox2.Text); if (comboBox1.SelectedIndex == 0) { sum = no1 + no2; textBox3.Text = Convert.ToString(sum); } if (comboBox1.SelectedIndex == 1) { sum = no1 - no2; textBox3.Text = Convert.ToString(sum); } if (comboBox1.SelectedIndex == 2) { sum = no1 * no2; textBox3.Text = Convert.ToString(sum); } if (comboBox1.SelectedIndex == 3) { if (no2 == 0) { textBox3.Text = "無解"; DialogResult = MessageBox.Show("除數不可為零", "注意", MessageBoxButtons.OK); } else { sum = no1 / no2; textBox3.Text = Convert.ToString(sum); } } } } } |
Direct link: https://paste.plurk.com/show/vhyCAIEaFxDyGBFZ1n68