private void btnCreation_Click(object sender, EventArgs e) { if (vehiculeRoulant != null) { MessageBox.Show("Instance déjà créée"); return; } VehiculeType vehiculeType = (VehiculeType)cbxTypeVehicule.SelectedIndex; switch (vehiculeType) { case VehiculeType.Camion: vehiculeRoulant = new Camion(); break; case VehiculeType.Voiture: vehiculeRoulant = new Voiture(); break; case VehiculeType.Moto: vehiculeRoulant = new Moto(); break; default: throw new Exception(string.Format("Unkown Vehicule Type : {0}", cbxTypeVehicule.Text)); } ToggleButtons(); txbCharge.Text = vehiculeRoulant.Charge.ToString(); txbDistance.Text = vehiculeRoulant.Distance.ToString(); txbPassagers.Text = vehiculeRoulant.Passagers.ToString(); txbVitesseMaxi.Text = vehiculeRoulant.VitesseMaxi.ToString(); txbVitesseMini.Text = vehiculeRoulant.VitesseMini.ToString(); }
private void btnDestruction_Click(object sender, EventArgs e) { vehiculeRoulant = null; ToggleButtons(); // 1ère facon de faire : /* * txbCharge.Text = ""; * txbConsommation.Text = ""; * txbDistance.Text = ""; * txbPassagers.Text = ""; * txbVitesseMaxi.Text = ""; * txbVitesseMini.Text = "";*/ // 2ème facon de faire : foreach (var control in gbxVehicule.Controls) { if (control is TextBox) { (control as TextBox).Clear(); } } }