public void OpenFileDialog() { //Configure the file dialog CharacterSheetOpenFileDialog.FileName = "Character"; CharacterSheetOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterSheetOpenFileDialog.Filter = "Text documents (*.txt)|*.txt| All Files(*.*)|*.*"; CharacterSheetOpenFileDialog.DefaultExt = ".txt"; //Open file dialog var _result = CharacterSheetOpenFileDialog.ShowDialog(); if (_result != DialogResult.Cancel) { try { using (StreamReader inputStream = new StreamReader( File.Open(CharacterSheetOpenFileDialog.FileName, FileMode.Open))) { //Cleanup inputStream.Close(); inputStream.Dispose(); } } catch (Exception exception) { MessageBox.Show("Error " + exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Open Character Sheet /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenToolStripButton_Click(object sender, EventArgs e) { //configure the file dialog CharacterSheetOpenFileDialog.FileName = "CharacterSheet.txt"; CharacterSheetOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterSheetOpenFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files{*.*)|*.*"; //open the file dialog var result = CharacterSheetOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { try { //Open the stream for reading using (StreamReader inputStream = new StreamReader(File.Open(CharacterSheetOpenFileDialog.FileName, FileMode.Open))) { //Read from file Program.hero.FirstName = inputStream.ReadLine(); Program.hero.LastName = inputStream.ReadLine(); //Physical Ability Program.hero.Fighting = inputStream.ReadLine(); Program.hero.Agility = inputStream.ReadLine(); Program.hero.Strength = inputStream.ReadLine(); Program.hero.Endurance = inputStream.ReadLine(); //Mental Abillity Program.hero.Reason = inputStream.ReadLine(); Program.hero.Intuition = inputStream.ReadLine(); Program.hero.Psyche = inputStream.ReadLine(); Program.hero.Popularity = inputStream.ReadLine(); Program.hero.Powers.Clear(); Program.hero.Powers.Add(inputStream.ReadLine()); Program.hero.Powers.Add(inputStream.ReadLine()); Program.hero.Powers.Add(inputStream.ReadLine()); Program.hero.Powers.Add(inputStream.ReadLine()); //Clean up inputStream.Close(); inputStream.Dispose(); } } catch (IOException exception) { MessageBox.Show("ERROR" + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadHero(); } }
public void OpenFileDialog() { //Configure the file dialog CharacterSheetOpenFileDialog.FileName = "Character"; CharacterSheetOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterSheetOpenFileDialog.Filter = "Text documents (*.txt)|*.txt| All Files(*.*)|*.*"; CharacterSheetOpenFileDialog.DefaultExt = ".txt"; //Open file dialog var _result = CharacterSheetOpenFileDialog.ShowDialog(); if (_result != DialogResult.Cancel) { try { using (StreamReader inputStream = new StreamReader( File.Open(CharacterSheetOpenFileDialog.FileName, FileMode.Open))) { //Read stuff from the file into the Product object Program.characterPortfolio.Identity.FirstName = inputStream.ReadLine(); Program.characterPortfolio.Identity.LastName = inputStream.ReadLine(); Program.characterPortfolio.Strength = inputStream.ReadLine(); Program.characterPortfolio.Dexterity = inputStream.ReadLine(); Program.characterPortfolio.Endurance = inputStream.ReadLine(); Program.characterPortfolio.Intellect = inputStream.ReadLine(); Program.characterPortfolio.Education = inputStream.ReadLine(); Program.characterPortfolio.SocialStanding = inputStream.ReadLine(); Skill1Label.Text = inputStream.ReadLine(); Skill2Label.Text = inputStream.ReadLine(); Skill3Label.Text = inputStream.ReadLine(); Skill4Label.Text = inputStream.ReadLine(); //Cleanup inputStream.Close(); inputStream.Dispose(); } } catch (Exception exception) { MessageBox.Show("Error " + exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } //Fill up form fields with character information from file //Identity FirstNameDataLabel.Text = Program.characterPortfolio.Identity.FirstName; LastNameDataLabel.Text = Program.characterPortfolio.Identity.LastName; //Characteristics StrengthDataLabel.Text = Program.characterPortfolio.Strength; DexterityDataLabel.Text = Program.characterPortfolio.Dexterity; EnduranceDataLabel.Text = Program.characterPortfolio.Endurance; IntellectDataLabel.Text = Program.characterPortfolio.Intellect; EducationDataLabel.Text = Program.characterPortfolio.Education; SocialStandingDataLabel.Text = Program.characterPortfolio.SocialStanding; StrengthDataLabel.Text = Program.characterPortfolio.Strength; DexterityDataLabel.Text = Program.characterPortfolio.Dexterity; EnduranceDataLabel.Text = Program.characterPortfolio.Endurance; IntellectDataLabel.Text = Program.characterPortfolio.Intellect; EducationDataLabel.Text = Program.characterPortfolio.Education; SocialStandingDataLabel.Text = Program.characterPortfolio.SocialStanding; CharacterFirstNameDataLabel.Text = Program.characterPortfolio.Identity.FirstName; CharacterLastNameDataLabel.Text = Program.characterPortfolio.Identity.LastName; CharacterStrengthDataLabel.Text = Program.characterPortfolio.Strength; CharacterDexterityDataLabel.Text = Program.characterPortfolio.Dexterity; CharacterEnduranceDataLabel.Text = Program.characterPortfolio.Endurance; CharacterIntellectDataLabel.Text = Program.characterPortfolio.Intellect; CharacterEducationDataLabel.Text = Program.characterPortfolio.Education; CharacterSocialStandingDataLabel.Text = Program.characterPortfolio.SocialStanding; CharacterSkill1DataLabel.Text = Skill1Label.Text; CharacterSkill2DataLabel.Text = Skill2Label.Text; CharacterSkill3DataLabel.Text = Skill3Label.Text; CharacterSkill4DataLabel.Text = Skill4Label.Text; }