}//end StatesForm() /// <summary> /// Handles the Click event of the NextQuestionButton control. /// Checks if the user got the name of the state's capital correct /// or if they got it wrong. /// </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 NextQuestionButton_Click(object sender, EventArgs e) { TimeLeft = 15; CountDownTimer.Start(); //Reset the timer back to 15 seconds //and start it again ClearSelectedBln = false; CapitalsListBox.ClearSelected(); ClearSelectedBln = true; //ClearSelected in the CapitalsListBox, but does not go into the code of //the CapitalsListBox_SelectedIndexChanged method CapitalsListBox.Enabled = true; TimerTextBox.Text = TimeLeft.ToString(); if (AttemptsCounter == 51) { AttemptsTextBox.Text = (AttemptsCounter).ToString(); CorrectTextBox.Text = CorrectCounter.ToString(); System.Threading.Thread.Sleep(2000); this.Close(); } else { //Remove the state from the list of states if the user gets it correct StatesIndex = R.Next(50 - AttemptsCounter); //Updates the new random int which will choose a new state StatesTextBox.Text = States[StatesIndex]; AttemptsTextBox.Text = (AttemptsCounter).ToString(); CorrectTextBox.Text = CorrectCounter.ToString(); } }//end NextQuestionButton_Click(object sender, EventArgs e)
private static bool ClearSelectedBln = false; //For not going into the changedINdex method //for the list box when the ClearSelected method //is called /// <summary> /// Initializes a new instance of the <see cref="StatesForm"/> class. /// Starts the StatesForm. IT will read in from the text fill /// and set up the first question /// </summary> public StatesForm() { InitializeComponent(); StreamReader reader; //for reading in the text file string strIn; //reads in each line from the text file try { reader = new StreamReader("..\\..\\TextFolder\\StatesCaps.txt"); while (reader.Peek() != -1) { strIn = reader.ReadLine(); //gets the line String[] fields = strIn.Split(','); //splits on the delimiter ',' States.Add(fields[1]); Capitals.Add(fields[0]); StatesCaps.Add(fields[1], fields[0]); //Adds the proper string to the proper List or container } reader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } Capitals.Sort(); CapitalsListBox.DataSource = Capitals; //Adds all the capitals the list box StatesIndex = R.Next(50); StatesTextBox.Text = States[StatesIndex]; AttemptsTextBox.Text = (AttemptsCounter).ToString(); CorrectTextBox.Text = CorrectCounter.ToString(); TimerTextBox.BackColor = Color.White; TimerTextBox.ForeColor = Color.Red; TimerTextBox.ReadOnly = true; TimerTextBox.Text = TimeLeft.ToString(); CountDownTimer.Start(); ClearSelectedBln = false; CapitalsListBox.ClearSelected(); ClearSelectedBln = true; //ClearSelected in the CapitalsListBox, but does not go into the code of //the CapitalsListBox_SelectedIndexChanged method CapitalsListBox.Enabled = true; AttemptsCounter++; //First attempt will start AttemptsTextBox.Text = (AttemptsCounter).ToString(); CorrectTextBox.Text = CorrectCounter.ToString(); }//end StatesForm()