// To temporarily disable snaplines while moving a control (lines), HOLD ALT. // Good tutorial for resher on mySQL database: https://www.youtube.com/watch?v=IcD9Jffstmw // *****IMPORTANT********* // SQL EXPRESS LOCALDB.exe needed for others to run program on their PC's: https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb?view=sql-server-ver15 // ****************** // TODO: Music Add to Project: https://stackoverflow.com/questions/34116886/how-to-play-background-music-in-a-c-sharp-console-application // TODO: Auto-update the program addition: https://www.youtube.com/watch?v=h1SJAUXV-YY // Tutorial used for VisualBasic Framework regarding the input window for submitting final score: https://www.youtube.com/watch?v=nxF3CI5SYJs using System; using System.ComponentModel; using System.Windows.Forms; using System.Configuration; using System.Data.SqlClient; using System.Diagnostics; using MySql.Data.MySqlClient; using System.Drawing; using System.Collections.Generic; using System.Linq; using System.Threading; using Microsoft.VisualBasic; using System.Runtime.Remoting.Messaging; namespace CSharp_GeographyGame { public partial class mainForm : Form { string connectionString; SqlConnection connection; double corCount = 0; double perNum = 0.0; bool clockIt = false; string nID; public mainForm(string inName) { nID = inName; InitializeComponent(); bgWorker.DoWork += bgWorker_DoWork; bgWorker.ProgressChanged += bgWorker_ProgressChanged; bgWorker.WorkerReportsProgress = true; lblUsername.Text = lblUsername.Text + " " + nID; userToolStripMenuItem.Text = lblUsername.Text; connectionString = ConfigurationManager.ConnectionStrings["CSharp_GeographyGame.Properties.Settings.userScoresConnectionString"].ConnectionString; } private void mainForm_Shown(object sender, EventArgs e) { bgWorker.RunWorkerAsync(); } private void insertDataLocally(double scoreID, string sqlFormattedDate) { //// FOR LOCAL DATABASE string con = "INSERT INTO USMapscores ([Name], [Score], [Time], [Date]) VALUES(@name, @score, @time, @date)"; using (connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand(con, connection)) { try { connection.Open(); } catch (Exception ex) { Console.WriteLine(ex.Message); } command.Parameters.AddWithValue("@name", nID); command.Parameters.AddWithValue("@score", scoreID); command.Parameters.AddWithValue("@time", lblClock.Text); command.Parameters.AddWithValue("@date", sqlFormattedDate); int result = command.ExecuteNonQuery(); // Check Error if (result < 0) MessageBox.Show("Error inserting data into database!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); connection.Close(); } } private void insertDataOnline(double scoreID, string sqlFormattedDate) { //// FOR ONLINE DATABASE string conWeb = "Server = remotemysql.com; Port = 3306; database = 2Ds6YxqaDW; username = 2Ds6YxqaDW; password = VJKMThFkcO"; MySqlConnection connTwo = new MySqlConnection(conWeb); MySqlCommand commWeb = connTwo.CreateCommand(); commWeb.CommandType = System.Data.CommandType.Text; commWeb.CommandText = "INSERT INTO onUSmapscores (Name, Score, Time, Date) VALUES(@name, @score, @time, @date)"; commWeb.Parameters.AddWithValue("@name", nID); commWeb.Parameters.AddWithValue("@score", scoreID); commWeb.Parameters.AddWithValue("@time", lblClock.Text); commWeb.Parameters.AddWithValue("@date", sqlFormattedDate); try { connTwo.Open(); } catch (Exception ex) { MessageBox.Show(ex.Message); } commWeb.ExecuteNonQuery(); connTwo.Close(); } private void vbScoreInputDialog(double scoreID, string sqlFormattedDate) { //// Using microsoft.visualbasic reference allowing the user to choose where to submit his score (allows offline score submission) string message, title, defaultValue; object myValue; message = "Would you like to submit your results to the Local, Online, or Both databases?\n" + "Type the following in the textbox below:\n" + "Local\n" + "Online\n" + "Both"; title = "Score Submission"; defaultValue = "Both"; bool validSelection = false; do { myValue = Interaction.InputBox(message, title, defaultValue); // input box if ((string)myValue == "") { object uChoice = Microsoft.VisualBasic.Interaction.MsgBox("Are you sure you don't want to submit your score?", MsgBoxStyle.YesNo, "Score Submission"); if ((int)uChoice == 6) { System.Environment.Exit(0); } else { // do nothing, reset back to original input box } } else if ((string)myValue == "Local" || (string)myValue == "local") { insertDataLocally(scoreID, sqlFormattedDate); validSelection = true; } else if ((string)myValue == "Online" || (string)myValue == "online") { insertDataOnline(scoreID, sqlFormattedDate); validSelection = true; } else if ((string)myValue == "Both" || (string)myValue == "both") { insertDataLocally(scoreID, sqlFormattedDate); insertDataOnline(scoreID, sqlFormattedDate); validSelection = true; } else { Microsoft.VisualBasic.Interaction.MsgBox("Wrong input entered... Please try again and this time, read."); } } while (validSelection == false); ///// } private void BrowserCheck() { var RunningProcessPaths = ProcessFileNameFinderClass.GetAllRunningProcessFilePaths(); if (RunningProcessPaths.Contains("firefox.exe")) { foreach (Process proc in Process.GetProcessesByName("firefox")) proc.Kill(); MessageBox.Show(new Form { TopMost = true }, "Firefox was open... No no no.", "Suspicious", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } if (RunningProcessPaths.Contains("chrome.exe")) { foreach (Process proc in Process.GetProcessesByName("chrome")) proc.Kill(); MessageBox.Show(new Form { TopMost = true }, "Chrome was open... No no no.", "Suspicious", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } if (RunningProcessPaths.Contains("msedge.exe")) { foreach (Process proc in Process.GetProcessesByName("msedge")) proc.Kill(); // reference: https://social.msdn.microsoft.com/Forums/vstudio/en-US/50ecbcf2-d2d3-4f21-9775-5b8be1bd4346/how-to-terminate-a-process-in-c?forum=csharpgeneral MessageBox.Show(new Form { TopMost = true }, "Microsoft Edge was open... No no no.", "Suspicious", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } private void bgWorker_DoWork(object sender, DoWorkEventArgs e) { double cCount = 0; double prev = 0; pbStatus.Invoke((MethodInvoker)(() => pbStatus.Minimum = 0)); pbStatus.Invoke((MethodInvoker)(() => pbStatus.Maximum = 50)); while (true) { cCount = corCount; if (cCount > prev) { prev = cCount; pbStatus.Invoke((MethodInvoker)(() => pbStatus.Increment(1))); bgWorker.ReportProgress((int)cCount); //Thread.Sleep(1000); } Application.DoEvents(); if (cCount == 50) { break; // ***is needed for the bgWorker to end to run bgWorker_RunWorkerCompleted } } } private void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { pbStatus.Value = e.ProgressPercentage; } private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled) { MessageBox.Show("Error. I suck."); } else if (e.Error != null) { MessageBox.Show("Ran into an unknown error... I really suck."); } else { if (lblCorrect.Text.ToString() == lblTotal.Text.ToString()) { lblClock.ForeColor = System.Drawing.Color.Green; } timerClock.Stop(); i = 0; clockIt = false; tbsEnableDisable(); System.Diagnostics.Process.Start("https://media3.giphy.com/media/g9582DNuQppxC/200.gif"); string xTract = lblPercentage.Text.Trim(new Char[] { '%', '*', '.' }); int xConversion; Int32.TryParse(xTract, out xConversion); double scoreID = xConversion; DateTime myDateTime = DateTime.Now; string sqlFormattedDate = myDateTime.ToString("MM-dd-yyyy HH:mm:ss.fff"); vbScoreInputDialog(scoreID, sqlFormattedDate); DialogResult diaBox; diaBox = MessageBox.Show(new Form { TopMost = true }, "Great job, you are a genius! Would you like to reset the map (yes) or keep showing your glorious results (no)?", "Congratulations", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (diaBox == DialogResult.Yes) { lblClock.ForeColor = System.Drawing.Color.Black; ResetText(); lblClock.Text = "00:00:00"; pbStatus.Value = 0; lblPercentage.Text = "%"; clearTextBoxes(); btnPause.Enabled = false; btnQuit.Enabled = false; } if (diaBox == DialogResult.No) { btnBegin.Enabled = false; btnPause.Enabled = false; btnQuit.Enabled = false; } } } private void capitalsFormToolStripMenuItem_Click(object sender, EventArgs e) { bool isOpen = false; foreach (Form F in Application.OpenForms) { if (F.Name == "capitalsForm") { isOpen = true; F.BringToFront(); } } if (isOpen == false) { capitalsForm cap = new capitalsForm(nID); cap.Show(); } /* // Important addition if I wanted to close this form before opening up another // if (bgWorkerBrowsers.IsBusy) { bgWorkerBrowsers.CancelAsync(); } this.Hide(); */ } private void viewScoresToolStripMenuItem_Click(object sender, EventArgs e) { bool isOpen = false; foreach (Form F in Application.OpenForms) { if (F.Name == "dbscoresForm") { isOpen = true; F.BringToFront(); } } if (isOpen == false) { dbscoresForm dbF = new dbscoresForm(); dbF.Show(); } } private void stateEntryDatesToolStripMenuItem1_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("https://www.enchantedlearning.com/usa/states/statehood.shtml"); } private void trainerInformationToolStripMenuItem_Click_1(object sender, EventArgs e) { bool isOpen = false; foreach (Form F in Application.OpenForms) { if (F.Name == "infoForm") { isOpen = true; F.BringToFront(); } } if (isOpen == false) { infoForm inf = new infoForm(); inf.Show(); } } private void capitalsOfEachStateToolStripMenuItem_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("https://www.britannica.com/topic/list-of-state-capitals-in-the-United-States-2119210"); } private void mapOfStatesCapitalsToolStripMenuItem_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("https://i.pinimg.com/originals/dc/43/9b/dc439bcdc9241bed795275063616fec0.jpg"); } private void restartComputerToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult diaBox; diaBox = MessageBox.Show(new Form { TopMost = true }, "Are you sure you would like to restart your computer?", "Restart Computer", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (diaBox == DialogResult.Yes) { //Code referenced: https://stackoverflow.com/questions/1215139/reboot-machine-from-a-c-wpf-app System.Diagnostics.Process.Start("shutdown.exe", "-r -t 0"); } if (diaBox == DialogResult.No) { return; } } private void disableWebBrowsersToolStripMenuItem_Click(object sender, EventArgs e) // FIGURE OUT CLEVER WAY TO GIVE WARNING { if (disableWebBrowsersToolStripMenuItem.Checked == true) { disableWebBrowsersToolStripMenuItem.BackColor = System.Drawing.Color.LightYellow; bgWorkerBrowsers.RunWorkerAsync(); } else { disableWebBrowsersToolStripMenuItem.BackColor = System.Drawing.Color.WhiteSmoke; bgWorkerBrowsers.CancelAsync(); } } int i = 0; private void timerClock_Tick(object sender, EventArgs e) { i++; if (lblClock.ForeColor == System.Drawing.Color.Red) { lblClock.ForeColor = System.Drawing.Color.Blue; } TimeSpan time = TimeSpan.FromSeconds(i); lblClock.Text = time.ToString(@"hh\:mm\:ss"); } private void btnBegin_Click(object sender, EventArgs e) { clockIt = true; tbsEnableDisable(); lblClock.ForeColor = System.Drawing.Color.Blue; timerClock.Stop(); timerClock.Start(); btnBegin.Enabled = false; if (btnPause.Enabled == false || btnQuit.Enabled == false) { btnPause.Enabled = true; btnQuit.Enabled = true; } } private void btnPause_Click(object sender, EventArgs e) { clockIt = false; timerClock.Stop(); tbsClearIncorrectText(); // recently added feature 10/29/2020 - Removes incorrect text from enabled textboxes tbsEnableDisable(); lblClock.ForeColor = System.Drawing.Color.Red; if (btnBegin.Enabled == false) { btnBegin.Text = "Resume"; btnBegin.Enabled = true; } btnPause.Enabled = false; } private void btnQuit_Click(object sender, EventArgs e) { timerClock.Stop(); string xTract = lblPercentage.Text.Trim(new Char[] { '%', '*', '.' }); int xConversion; Int32.TryParse(xTract, out xConversion); double scoreID = xConversion; DateTime myDateTime = DateTime.Now; string sqlFormattedDate = myDateTime.ToString("MM-dd-yyyy HH:mm:ss.fff"); vbScoreInputDialog(scoreID, sqlFormattedDate); i = 0; clockIt = false; lblClock.ForeColor = System.Drawing.Color.Black; lblClock.Text = "00:00:00"; lblCorrect.Text = 0.ToString(); lblPercentage.Text = "%"; pbStatus.Value = 0; tbsFillCorrectStates(); // for this feature to work, the function tbsEnableDisable must be moved below current function. clearTextBoxes must move to end of function. tbsEnableDisable(); MessageBox.Show(new Form { TopMost = true }, "Your score was submitted. The states you missed are displayed with a misty red " + "background and an asterick next to it. Once you close this window, the map will reset and you can give it another go!", "Score Submitted"); if (btnBegin.Enabled == false || btnPause.Enabled == false) { btnBegin.Text = "Begin"; btnBegin.Enabled = true; btnPause.Enabled = true; } btnPause.Enabled = false; btnQuit.Enabled = false; clearTextBoxes(); } private void tbsFillCorrectStates() { string[] correctStates = new string[50] { "*Delaware", "*Pennsylvania", "*New Jersey", "*Georgia", "*Connecticut", "*Massachusetts", "*Maryland", "*South Carolina", "*New Hampshire", "*Virginia", "*New York", "*North Carolina", "*Rhode Island", "*Vermont", "*Kentucky", "*Tennessee", "*Ohio", "*Louisiana", "*Indiana", "*Mississippi", "*Illinois", "*Alabama", "*Maine", "*Missouri", "*Arkansas", "*Michigan", "*Florida", "*Texas", "*Iowa", "*Wisconsin", "*California", "*Minnesota", "*Oregon", "*Kansas", "*West Virginia", "*Nevada", "*Nebraska", "*Colorado", "*North Dakota", "*South Dakota", "*Montana", "*Washington", "*Idaho", "*Wyoming", "*Utah", "*Oklahoma", "*New Mexico", "*Arizona", "*Alaska", "*Hawaii" }; var textboxArray = new[] { tb1, tb2, tb3, tb4, tb5, tb6, tb7, tb8, tb9, tb10, tb11, tb12, tb13, tb14, tb15, tb16, tb17, tb18, tb19, tb20, tb21, tb22, tb23, tb24, tb25, tb26, tb27, tb28, tb29, tb30, tb31, tb32, tb33, tb34, tb35, tb36, tb37, tb38, tb39, tb40, tb41, tb42, tb43, tb44, tb45, tb46, tb47, tb48, tb49, tb50 }; for (int i = 0; i < 50; i++) { if (textboxArray[i].Enabled == false && !String.IsNullOrEmpty((textboxArray[i]).Text)) { // Do nothing, keep correct answers written by user } else { textboxArray[i].BackColor = System.Drawing.Color.MistyRose; textboxArray[i].Text = correctStates[i]; } } } private void PercentageFormula() { perNum = ((corCount / 50) * 100); lblPercentage.Text = perNum.ToString("0.###") + "%"; } private void clearTextBoxes() { foreach (Control tb in this.Controls) { if (tb is TextBox) { ((TextBox)tb).Text = String.Empty; ((TextBox)tb).BackColor = SystemColors.Window; // Window is correct over System.Drawing.Color.White which fixes the disabled textboxes color } } } private void tbsClearIncorrectText() { foreach (Control tb in this.Controls) { if (tb is TextBox) { if (((TextBox)tb).Enabled == true && !String.IsNullOrEmpty(((TextBox)tb).Text)) { ((TextBox)tb).Text = String.Empty; } } } } private void tbsEnableDisable() { if (clockIt == true) { foreach (Control tb in this.Controls) { if (tb is TextBox) { ((TextBox)tb).Enabled = true; if (!String.IsNullOrEmpty(((TextBox)tb).Text)) // recently added feature 10/29/2020 - Needed so Correct States are not enabled for editing during pause { ((TextBox)tb).Enabled = false; } } } } else { foreach (Control tb in this.Controls) { if (tb is TextBox) { ((TextBox)tb).Enabled = false; } } } } private void tb1_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb1.Text, "delaware", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb1.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb2_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb2.Text, "pennsylvania", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb2.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb3_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb3.Text, "new jersey", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb3.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb4_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb4.Text, "georgia", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb4.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb5_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb5.Text, "connecticut", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb5.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb6_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb6.Text, "massachusetts", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb6.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb7_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb7.Text, "maryland", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb7.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb8_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb8.Text, "south carolina", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb8.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb9_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb9.Text, "new hampshire", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb9.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb10_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb10.Text, "virginia", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb10.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb11_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb11.Text, "new york", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb11.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb12_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb12.Text, "north carolina", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb12.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb13_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb13.Text, "rhode island", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb13.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb14_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb14.Text, "vermont", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb14.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb15_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb15.Text, "kentucky", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb15.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb16_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb16.Text, "tennessee", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb16.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb17_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb17.Text, "ohio", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb17.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb18_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb18.Text, "louisiana", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb18.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb19_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb19.Text, "indiana", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb19.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb20_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb20.Text, "mississippi", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb20.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb21_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb21.Text, "illinois", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb21.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb22_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb22.Text, "alabama", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb22.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb23_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb23.Text, "maine", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb23.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb24_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb24.Text, "missouri", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb24.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb25_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb25.Text, "arkansas", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb25.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb26_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb26.Text, "michigan", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb26.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb27_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb27.Text, "florida", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb27.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb28_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb28.Text, "texas", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb28.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb29_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb29.Text, "iowa", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb29.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb30_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb30.Text, "wisconsin", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb30.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb31_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb31.Text, "california", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb31.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb32_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb32.Text, "minnesota", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb32.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb33_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb33.Text, "oregon", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb33.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb34_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb34.Text, "kansas", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb34.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb35_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb35.Text, "west virginia", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb35.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb36_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb36.Text, "nevada", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb36.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb37_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb37.Text, "nebraska", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb37.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb38_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb38.Text, "colorado", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb38.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb39_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb39.Text, "north dakota", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb39.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb40_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb40.Text, "south dakota", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb40.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb41_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb41.Text, "montana", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb41.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb42_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb42.Text, "washington", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb42.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb43_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb43.Text, "idaho", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb43.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb44_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb44.Text, "wyoming", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb44.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb45_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb45.Text, "utah", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb45.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb46_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb46.Text, "oklahoma", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb46.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb47_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb47.Text, "new mexico", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb47.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb48_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb48.Text, "arizona", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb48.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb49_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb49.Text, "alaska", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb49.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tb50_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; lblActiveText.Text = txt.Text; if (string.Compare(tb50.Text, "hawaii", true) == 0) { corCount++; lblCorrect.Text = corCount.ToString(); tb50.Enabled = false; lblActiveText.Text = string.Empty; PercentageFormula(); } } private void tbAll_Enter(object sender, EventArgs e) // this code enables each box which is focused to highlight a said color { ((TextBox)sender).BackColor = Color.Gold; } private void mainForm_Load(object sender, EventArgs e) { tbsEnableDisable(); btnPause.Enabled = false; btnQuit.Enabled = false; } private void mainForm_FormClosing(object sender, FormClosingEventArgs e) { bool isOpen = false; FormCollection formsOpen = Application.OpenForms; foreach (Form frm in formsOpen) { //iterate through if (frm.Name == "capitalsForm") { isOpen = true; return; } else { isOpen = false; } } if (isOpen == false) { FormProvider.gForm.Show(); } } private void tbAll_Leave(object sender, EventArgs e) { ((TextBox)sender).BackColor = Color.White; foreach (Control tb in this.Controls) { if (tb is TextBox) { if (tb.Enabled == false) ((TextBox)tb).BackColor = System.Drawing.Color.WhiteSmoke; } } } private void exitProgramToolStripMenuItem_Click(object sender, EventArgs e) { // This code list all of the processes running in the debug output window on the right side of screen //using System.Runtime.InteropServices; //[DllImport("kernel32.dll", SetLastError = true)] //[return: MarshalAs(UnmanagedType.Bool)] //static extern bool AllocConsole(); //foreach (var process in Process.GetProcesses()) //{ // AllocConsole(); // Console.WriteLine(process.ProcessName); //} //Console.ReadKey(); foreach (var process in Process.GetProcessesByName("CSharp_GeographyGame")) { process.Kill(); } this.Close(); Application.ExitThread(); Application.Exit(); } private void bgWorkerBrowsers_DoWork(object sender, DoWorkEventArgs e) { while (true) { if (bgWorkerBrowsers.CancellationPending) { e.Cancel = true; break; } BrowserCheck(); Thread.Sleep(3000); } } private void bgWorkerBrowsers_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled) { MessageBox.Show(new Form { TopMost = true }, "You may use your browsers again.", "Browsers Re-enabled"); } else if (e.Error != null) { MessageBox.Show("It's impossible to get here, or is it? :D"); } else { MessageBox.Show("Should NEVER get here :)"); } } private void goBackToGameMenuToolStripMenuItem_Click(object sender, EventArgs e) { FormProvider.gForm.Show(); //** Important addition **// if (bgWorkerBrowsers.IsBusy) { bgWorkerBrowsers.CancelAsync(); } this.Close(); } } }