using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace trackDesigner { public partial class addTrain : Form { /*-----*----- DATA MEMBERS -----*-----*/ private int trainSpeed = 0; private string trainColor; private int trainDir = 0; /*-----*----- EVENTS -----*-----*/ public event EventHandler NewTrain; /*-----*----- PROPERTIES -----*-----*/ public int speed { get { return trainSpeed; } } public string color { get { return trainColor; } } public int direction { get { return trainDir; } } public addTrain() { InitializeComponent(); } /*-----*----- METHODS -----*-----*/ /******************************************************************* Method Name: enableControls Purpose: Enables all controls on the form--used when a valid * location to initialize train is clicked Input: None Output: None *******************************************************************/ public void enableControls() { foreach (Control c in Controls) { c.Enabled = true; } } /*-----*----- EVENT HANDLERS -----*-----*/ private void btnCreateTrain_Click(object sender, EventArgs e) { int x; if (tbSpeed.Text.Length != 0) x = Convert.ToInt32(tbSpeed.Text); else x = 0; // set to 0 by default if (x >= 0 && x <= 10) // make sure valid speed entered. if not valid, form won't close bc { // event never gets raised in other form trainSpeed = x; int y; if(tbDirection.Text.Length != 0) y = Convert.ToInt32(tbDirection.Text); else y = 0; // set to 0 if no number entered if (y >= 0 && y <= 7) trainDir = y; else trainDir = 0; // set to 0 if bad number entered foreach (RadioButton rb in gbColor.Controls) { if (rb.Checked) { // set colors to system color names if (rb.Text == "Red") trainColor = "DarkRed"; else if (rb.Text == "Orange") trainColor = "DarkOrange"; else if (rb.Text == "Dark Green") trainColor = "DarkGreen"; else if (rb.Text == "Aqua") trainColor = "DarkTurquoise"; else if (rb.Text == "Light Blue") trainColor = "LightSkyBlue"; else if (rb.Text == "Violet") trainColor = "DarkViolet"; else if (rb.Text == "Pink") trainColor = "DeepPink"; else // white and yellow are already what they need to be trainColor = rb.Text; break; } } if (this.NewTrain != null) // raise event to redraw screen with train on it this.NewTrain(this, EventArgs.Empty); } } } }