Zebra0.com

csharp pizza

The form load event will laod the topping file if it exists. If not, it displays a message box.
It would be nice to lett the user select a file if the default one doesn't exist.

private void Form1_Load(object sender, EventArgs e)
{
   // Load the toppings from the file.
   String fileName = @"c:\mydata\pizzatoppings.txt";
   // Include using System.IO; to use File.Exists.
   if (File.Exists(fileName)) getToppings(fileName);
   else MessageBox.Show(fileName + " Not Found", "No toppings available", MessageBoxButtons.OK);
   // To do: Let the user select a file.
   // Add the click event for every control on the form.
   foreach (Control ctrl in this.Controls)
   {
       ctrl.Click += new EventHandler(Control_Click);
   }
   // Show cost at start for default size.
   CalculateCost();
}

private void Control_Click(object sender, EventArgs e)
{
   // This event handles the click event for every control on the form.
   CalculateCost();
}

private void CalculateCost()
{ 
   // TO-DO later
}

To do: If the topping file is missing, let the user select one.

End of lesson, Next lesson: Drawing Methods in C#