private void button1_Click(object sender, EventArgs e) { SE engineer = new SE(); Instrument instrument = null; //设置选中的乐器 if (this.radioButton1.Checked) { instrument = new Piano(); groupBox1.Text = Name; MessageBox.Show("钢琴在演奏!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (this.radioButton2.Checked) { instrument = new Violin(); groupBox1.Text = Name; MessageBox.Show("小提琴在演奏!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (this.radioButton3.Checked) { instrument = new Sachs(); groupBox1.Text = Name; MessageBox.Show("萨克斯在演奏!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } engineer.Play(); }
//格式化 public void init() { List <Instrument> engineers = new List <Instrument>(); SE jack = new SE("001", "王小毛", 22, Gender.famale, 100); SE joe = new SE("002", "周新宇", 23, Gender.male, 200); SE ema = new SE("003", "盖茨", 24, Gender.male, 300); engineers.Add(jack); engineers.Add(joe); engineers.Add(ema); //绑定DataGrideView对象 this.dataGridView1.DataSource = engineers; }