private void Start() { if (DiskNumInputBox.Equals(null) || DiskNumInputBox.BackColor == Color.Red) { return; } Towers = new Tower(int.Parse(DiskNumInputBox.Text)); TotalMovesLabel.Text = "Total Number of Moves: " + Towers.MovesLeft(); UpdateCurrentMove(); NextMoveButton.Enabled = true; StartButton.Enabled = false; DisplayTowers(); }
/// <summary> /// Handles the TextChanged event of the DiskNumInputBox control to only allow integer inputs. /// if non-integer is typed then text box changes back ground to red until only integers /// populate the text box /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void DiskNumInputBox_TextChanged(object sender, EventArgs e) { List <Char> chars = new List <Char>(DiskNumInputBox.Text.ToCharArray()); foreach (Char c in chars) { if (!Char.IsDigit(c)) { DiskNumInputBox.BackColor = Color.Red; return; } } DiskNumInputBox.ResetBackColor(); int NumDisks = int.Parse(DiskNumInputBox.Text); }