private void btnAdd_Click(object sender, EventArgs e) { string str = comboBoxShape.SelectedItem.ToString(); double arg1 = double.Parse(txtArg1.Text); double arg2 = double.Parse(txtArg2.Text); double density = double.Parse(txtDensity.Text); string strDispay = ""; switch (str) { case "球": Ball myBall = new Ball(arg1, density); strDispay = myBall.Info(); break; case "立方體": Cube myCube = new Cube(arg1, density); strDispay = myCube.Info(); break; case "圓柱體": Cylinder myCylinder = new Cylinder(arg1, arg2, density); strDispay = myCylinder.Info(); break; case "金字塔": Pyramid myPyramid = new Pyramid(arg1, arg2, density); strDispay = myPyramid.Info(); break; default: break; } txtBallAmount.Text = Ball.Amount.ToString(); txtCubeAmount.Text = Cube.Amount.ToString(); txtCylinderAmount.Text = Cylinder.Amount.ToString(); txtPyramidAmount.Text = Pyramid.Amount.ToString(); int totalAmount = Ball.Amount + Cube.Amount + Cylinder.Amount + Pyramid.Amount; txtTotalAmonut.Text = totalAmount.ToString(); txtMessage.AppendText(strDispay); }
private void button1_Click(object sender, EventArgs e) { string shape = comboBox2.SelectedItem.ToString(); switch (shape) { case "球": Ball ball = new Ball(Double.Parse(textBox2.Text), Double.Parse(textBox1.Text)); textBox8.AppendText(ball.ShapeProperty()); break; case "立方體": Cube cube = new Cube(Double.Parse(textBox2.Text), Double.Parse(textBox1.Text)); textBox8.AppendText(cube.ShapeProperty()); break; case "圓柱體": Cylinder cylinder = new Cylinder(Double.Parse(textBox2.Text), Double.Parse(textBox9.Text), Double.Parse(textBox1.Text)); textBox8.AppendText(cylinder.ShapeProperty()); break; case "金字塔": Pyramid pyramid = new Pyramid(Double.Parse(textBox2.Text), Double.Parse(textBox9.Text), Double.Parse(textBox1.Text)); textBox8.AppendText(pyramid.ShapeProperty()); break; default: break; } textBox8.AppendText("\r\n"); textBox3.Text = (Ball.Amount + Cube.Amount + Cylinder.Amount + Pyramid.Amount).ToString(); textBox4.Text = Ball.Amount.ToString(); textBox5.Text = Cube.Amount.ToString(); textBox6.Text = Cylinder.Amount.ToString(); textBox7.Text = Pyramid.Amount.ToString(); }