private void addButton_Click(object sender, EventArgs e) { Automobile car = new Automobile(); // Create an instance of the Automobile structure. GetData(ref car); // Get the data entered by the user. carList.Add(car); // Add the car object to the List. makeTextBox.Clear(); // Clear the TextBoxes. yearTextBox.Clear(); mileageTextBox.Clear(); makeTextBox.Focus(); // Reset the focus. }
private void GetData(ref Automobile auto) { try { auto.make = txtMake.Text; auto.year = int.Parse(txtYear.Text); auto.mileage = double.Parse(txtMileage.Text); }//end try catch (Exception ex) { MessageBox.Show(ex.Message); } //end catch } //end of void GetData method
private void GetData(ref Automobile car) { try { car.make = makeTextBox.Text; // Get the data from the TextBoxes. car.year = int.Parse(yearTextBox.Text); car.mileage = double.Parse(mileageTextBox.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); // Display the exception message. } }
private void addButton_Click(object sender, EventArgs e) { Automobile car = new Automobile(); GetData(ref car); carList.Add(car); makeTextBox.Clear(); yearTextBox.Clear(); mileageTextBox.Clear(); makeTextBox.Focus(); }
private void GetData(ref Automobile auto) { try { auto.make = makeTextBox.Text; auto.year = int.Parse(yearTextBox.Text); auto.mileage = double.Parse(mileageTextBox.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
} //end of void GetData method private void btnAddCar_Click(object sender, EventArgs e) { Automobile car = new Automobile(); GetData(ref car); carList.Add(car); //clear the boxes txtMake.Clear(); txtYear.Clear(); txtMileage.Clear(); //focus the cursor txtMake.Focus(); }//end of btnAddCar void method