/// <summary> /// This is the shared event handler for the SaveToolStripMenuItem and saveMenuStripButton click event /// This is the event handler for the SaveToolStripMenuItem click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void saveToolStripMenuItem_Click_1(object sender, EventArgs e) { //Configure the file dialog CharacterSheetSaveFileDialog.FileName = "Character"; CharacterSheetSaveFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterSheetSaveFileDialog.Filter = "Text documents (*.txt)|*.txt| All Files(*.*)|*.*"; CharacterSheetSaveFileDialog.DefaultExt = ".txt"; //Open file dialog var _result = CharacterSheetSaveFileDialog.ShowDialog(); if (_result != DialogResult.Cancel) { try { //Open stream to write using (StreamWriter outputStream = new StreamWriter( File.Open(CharacterSheetSaveFileDialog.FileName, FileMode.Create))) { //Cleanup outputStream.Close(); outputStream.Dispose(); } } catch (Exception exception) { MessageBox.Show("ERROR: " + exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } MessageBox.Show("File saved successfully!", "Saving...", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// This is the shared event handler for the SaveToolStripMenuItem and saveMenuStripButton click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveToolStripMenuItem_Click(object sender, EventArgs e) { //Configure the file dialog CharacterSheetSaveFileDialog.FileName = "Character"; CharacterSheetSaveFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterSheetSaveFileDialog.Filter = "Text documents (*.txt)|*.txt| All Files(*.*)|*.*"; CharacterSheetSaveFileDialog.DefaultExt = ".txt"; //Open file dialog var _result = CharacterSheetSaveFileDialog.ShowDialog(); if (_result != DialogResult.Cancel) { try { //Open stream to write using (StreamWriter outputStream = new StreamWriter( File.Open(CharacterSheetSaveFileDialog.FileName, FileMode.Create))) { //Write stuff to the file outputStream.WriteLine(Program.characterPortfolio.Identity.FirstName); outputStream.WriteLine(Program.characterPortfolio.Identity.LastName); outputStream.WriteLine(Program.characterPortfolio.Strength); outputStream.WriteLine(Program.characterPortfolio.Dexterity); outputStream.WriteLine(Program.characterPortfolio.Endurance); outputStream.WriteLine(Program.characterPortfolio.Intellect); outputStream.WriteLine(Program.characterPortfolio.Education); outputStream.WriteLine(Program.characterPortfolio.SocialStanding); outputStream.WriteLine(Skill1Label.Text); outputStream.WriteLine(Skill2Label.Text); outputStream.WriteLine(Skill3Label.Text); outputStream.WriteLine(Skill4Label.Text); //Cleanup outputStream.Close(); outputStream.Dispose(); } } catch (Exception exception) { MessageBox.Show("ERROR: " + exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } MessageBox.Show("File saved successfully!", "Saving...", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Saving Character Sheet /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveToolStripButton_Click(object sender, EventArgs e) { //configure the file dialog CharacterSheetSaveFileDialog.FileName = "CharacterSheet.txt"; CharacterSheetSaveFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterSheetSaveFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files{*.*)|*.*"; //open the file dialog var result = CharacterSheetSaveFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { //open the stream for writing using (StreamWriter outputStream = new StreamWriter(File.Open(CharacterSheetSaveFileDialog.FileName, FileMode.Create))) { //Write to File outputStream.WriteLine(Program.hero.FirstName); outputStream.WriteLine(Program.hero.LastName); //Physical Ability outputStream.WriteLine(Program.hero.Fighting); outputStream.WriteLine(Program.hero.Agility); outputStream.WriteLine(Program.hero.Strength); outputStream.WriteLine(Program.hero.Endurance); //Mental Ability outputStream.WriteLine(Program.hero.Reason); outputStream.WriteLine(Program.hero.Intuition); outputStream.WriteLine(Program.hero.Psyche); outputStream.WriteLine(Program.hero.Popularity); //cleanup outputStream.WriteLine(Program.hero.Powers[0]); outputStream.WriteLine(Program.hero.Powers[1]); outputStream.WriteLine(Program.hero.Powers[2]); outputStream.WriteLine(Program.hero.Powers[3]); outputStream.Close(); outputStream.Dispose(); //Give feedback to the user that the file has been saved MessageBox.Show("File Saved...", "Saving File...", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }