private void button2_Click(object sender, EventArgs e) { //Checks for blank height/width fields, if blank, they are set to default if ((string.IsNullOrEmpty(textBox2.Text)) || (string.IsNullOrEmpty(textBox3.Text))) { textBox2.Text = "25"; textBox3.Text = "25"; h = Convert.ToInt32(textBox2.Text); //converts String to Int w = Convert.ToInt32(textBox3.Text); //converts String to Int } else { h = Convert.ToInt32(textBox2.Text); //converts String to Int w = Convert.ToInt32(textBox3.Text); //converts String to Int } //Assigns Title and Author titleTextString = titleText.Text; authorTextString = authorText.Text; //Get Words into Array wordStringList = new String[wordCount]; //Generate new array of strings with numElements == numWords(wordCount) wordBank.Items.CopyTo(wordStringList, 0); //Listbox funtion to copy an item to the stringList //Checks to make sure form is accuratly filled out if ((wordCount > 0) && (h >= wordLength) && (w >= wordLength) && (h < 34) && (w < 37) ) { //Set Counts number of options if (checkBox2.Checked == true) { otherCounter++; validCheck = 1; } if (checkBox3.Checked == true) { otherCounter++; validCheck = 1; } if (checkBox4.Checked == true) { otherCounter++; validCheck = 1; } if (checkBox5.Checked == true) { otherCounter++; validCheck = 1; } //Sets options in option counter optionSelector = new String[otherCounter]; int index = 0; if (checkBox2.Checked == true) { optionSelector[index++] = "upDown"; } if (checkBox3.Checked == true) { optionSelector[index++] = "leftRight"; } if (checkBox4.Checked == true) { optionSelector[index++] = "rightLeft"; } if (checkBox5.Checked == true) { optionSelector[index++] = "diag"; } //Creates Puzzle and sends it the data needed to generate a puzzle myPuzzle = new WordPuzzle(h, w, optionSelector, wordCount, titleTextString, authorTextString, wordStringList, otherCounter); } else{ //Error message for too few words if(wordCount < 1){ MessageBox.Show("You Have Not Entered Enough Words"); } //Error message for small height else if (h < wordLength) { MessageBox.Show("You Height must be larger than your longest word"); } //Error message for small width else if (w < wordLength) { MessageBox.Show("Your Width must be larger than your longest word"); } //Error message for large width else if (w > 36) { MessageBox.Show("Your width is too big to fit on a sheet of paper"); } //Error message for large height else if (h > 33) { MessageBox.Show("Your height is too big to fit on a sheet of paper"); } //Error message if something else went terribly wrong else { MessageBox.Show("Some other error has occured, please contact tech support"); } } }
//Menu strip option to save puzzle private void saveToolStripMenuItem_Click(object sender, EventArgs e) { //Create Puzzle (One Must Be Created to Save) myPuzzle = new WordPuzzle(h, w, optionSelector, wordCount, titleTextString, authorTextString, wordStringList, otherCounter); //Launches saveFileDialog saveFileDialog1.Filter = "Text Files (*.txt) | *.txt"; //Sets permisable file types saveFileDialog1.ShowDialog(); //Sets a file path to the save location string path = saveFileDialog1.FileName; //Calls the save method from myPuzzle String save = Form1.myPuzzle.saveSettingToText(); //Writes Files File.WriteAllText(path, save); }