private void openToolStripMenuItem_Click(object sender, EventArgs e) { // configure the file dialog CharacterOpenFileDialog.FileName = "Chracter.txt"; CharacterOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterOpenFileDialog.Filter = "Text files (*.txt)|*.txt| All Files (*.*)|*.*"; // open the file dialog var result = CharacterOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { try { using (StreamReader inputString = new StreamReader( File.Open(CharacterOpenFileDialog.FileName, FileMode.Open))) { //inputString.ReadLine(character.Identity.FirstName); } } catch (IOException exception) { Debug.WriteLine("ERROR: " + exception.Message); } } }
private void OpenToolStripMenuItem_Click(object sender, EventArgs e) { CharacterOpenFileDialog.FileName = "Character.txt"; CharacterOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterOpenFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*"; var result = CharacterOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { using (StreamReader streamReader = new StreamReader( File.Open(CharacterOpenFileDialog.FileName, FileMode.Open))) { Program.character.Identity.FirstName = streamReader.ReadLine(); Program.character.Identity.LastName = streamReader.ReadLine(); Program.character.Dexterity = streamReader.ReadLine(); Program.character.Education = streamReader.ReadLine(); Program.character.Endurance = streamReader.ReadLine(); Program.character.Intellect = streamReader.ReadLine(); Program.character.SocialStanding = streamReader.ReadLine(); Program.character.Strength = streamReader.ReadLine(); Program.character.Skills.Add(streamReader.ReadLine()); Program.character.Skills.Add(streamReader.ReadLine()); Program.character.Skills.Add(streamReader.ReadLine()); Program.character.Skills.Add(streamReader.ReadLine()); streamReader.Close(); streamReader.Dispose(); } MessageBox.Show("File loaded succesfully"); MainTabControl.SelectedIndex = 3; } }
/// <summary> /// This is the method to open a Character Portfolio from a file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenFile(object sender, EventArgs e) { // configure the file dialog CharacterOpenFileDialog.FileName = "Character.txt"; CharacterOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterOpenFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*"; // open the file dialog var result = CharacterOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { try { // Open the streawm for reading using (StreamReader inputStream = new StreamReader( File.Open(CharacterOpenFileDialog.FileName, FileMode.Open))) { // read from the file 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(); Program.characterPortfolio.Skills[0].Name = inputStream.ReadLine(); Program.characterPortfolio.Skills[1].Name = inputStream.ReadLine(); Program.characterPortfolio.Skills[2].Name = inputStream.ReadLine(); Program.characterPortfolio.Skills[3].Name = inputStream.ReadLine(); // cleanup inputStream.Close(); inputStream.Dispose(); } NextButton_Click(sender, e); } catch (IOException exception) { // error handler Debug.WriteLine("ERROR: " + exception.Message); MessageBox.Show("ERROR: " + exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (FormatException exception) { // error handler Debug.WriteLine("ERROR: " + exception.Message); MessageBox.Show("ERROR: " + exception.Message + "\n\nPlease select the appropriate file type", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void openToolStripButton_Click(object sender, EventArgs e) { //configure save file dialog box CharacterOpenFileDialog.FileName = "Character.txt"; CharacterOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterOpenFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; //Open Svae File Dialog var ShowDialog = CharacterOpenFileDialog.ShowDialog(); if (ShowDialog != DialogResult.Cancel) { try { //open Sterem Writer to write using (StreamReader inputStream = new StreamReader( File.Open(CharacterOpenFileDialog.FileName, FileMode.Open))) { //Write strings to File Program.character.HeroName = inputStream.ReadLine(); Program.character.FirstName = inputStream.ReadLine(); Program.character.LastName = inputStream.ReadLine(); Program.character.Fighting = inputStream.ReadLine(); Program.character.Agility = inputStream.ReadLine(); Program.character.Strength = inputStream.ReadLine(); Program.character.Endurance = inputStream.ReadLine(); Program.character.Reason = inputStream.ReadLine(); Program.character.Intution = inputStream.ReadLine(); Program.character.Psyche = inputStream.ReadLine(); Program.character.Popularity = inputStream.ReadLine(); //Program.character.HeroNa //Program.character.HeroNa //Program.character.HeroNa //Program.character.HeroNa // close inputStream.Close(); inputStream.Dispose(); } MessageBox.Show("File Retrieved Succesfully!", "Opened", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (IOException exception) { Debug.WriteLine("ERROR: " + exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void openToolStripButton_Click(object sender, EventArgs e) { CharacterOpenFileDialog.FileName = "Student.txt"; CharacterOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterOpenFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*"; // open the file dialog var result = CharacterOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { try { // Open your stream to read using (StreamReader inputStream = new StreamReader( File.Open(CharacterOpenFileDialog.FileName, FileMode.Open))) { // Read stuff into the Student class Program.character.FirstName = inputStream.ReadLine(); Program.character.LastName = inputStream.ReadLine(); Program.character.Strength = inputStream.ReadLine(); Program.character.Dexterity = inputStream.ReadLine(); Program.character.Constitution = inputStream.ReadLine(); Program.character.Intelligence = inputStream.ReadLine(); Program.character.Wisdom = inputStream.ReadLine(); Program.character.Charisma = inputStream.ReadLine(); Program.character.Inventory[0].Description = inputStream.ReadLine(); Program.character.Inventory[1].Description = inputStream.ReadLine(); Program.character.Inventory[2].Description = inputStream.ReadLine(); Program.character.Inventory[3].Description = inputStream.ReadLine(); CharacterSheetLoad(); // cleanup inputStream.Close(); inputStream.Dispose(); } } catch (IOException exception) { MessageBox.Show("Error: " + exception.Message, "File I/O Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Thie is event handler openFile click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void openToolStripMenuItem_Click(object sender, EventArgs e) { // configure the file dialog CharacterSaveFileDialog.FileName = "Character.txt"; CharacterSaveFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterSaveFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*"; // open file dialog - Modal Form var result = CharacterOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { try { // open file to write using (StreamReader inputStream = new StreamReader( File.Open(CharacterOpenFileDialog.FileName, FileMode.Create))) { // write stuff to the file Program.characters.Firstname = inputStream.ReadLine(); Program.characters.Lastname = inputStream.ReadLine(); Program.characters.Strength = inputStream.ReadLine(); Program.characters.Dexterity = inputStream.ReadLine(); Program.characters.Constitution = inputStream.ReadLine(); Program.items = inputStream.ReadLine(); // close the file inputStream.Close(); // dispose of the memory inputStream.Dispose(); } } catch (IOException exception) { MessageBox.Show("Error: " + exception.Message, "File I/O Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// This method handles the Open File event on the strip and tool menus on Character /// Generator Form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenToolStripMenuItem_Click(object sender, EventArgs e) { //configure open file dialog CharacterOpenFileDialog.FileName = "Character.txt"; CharacterOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterOpenFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*"; //open the file dialog var result = CharacterOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { using (StreamReader inputStream = new StreamReader( File.Open(CharacterOpenFileDialog.FileName, FileMode.Open))) { try { //read file Program.character.FirstName = inputStream.ReadLine(); Program.character.LastName = inputStream.ReadLine(); CharacterNameTextBox.Text = Program.character.FirstName + " " + Program.character.LastName; Program.character.Strength = inputStream.ReadLine(); Program.character.Dexterity = inputStream.ReadLine(); Program.character.Constitution = inputStream.ReadLine(); Program.character.Intelligence = inputStream.ReadLine(); Program.character.Wisdom = inputStream.ReadLine(); Program.character.Charisma = inputStream.ReadLine(); inputStream.Close(); inputStream.Dispose(); MainTabControl_SelectedIndexChanged(sender, e); } catch (IOException exception) { MessageBox.Show("Error: " + exception.Message, "File I/O Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
/// <summary> /// This is the shared event handler for the openToolStripMenuItem Click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void openToolStripMenuItem_Click(object sender, EventArgs e) { // configuration for openFileDialog CharacterOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterOpenFileDialog.FileName = "Character.txt"; CharacterOpenFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"; var result = CharacterOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { // open file stream to read using (StreamReader inputStream = new StreamReader( File.Open(CharacterOpenFileDialog.FileName, FileMode.Open))) { // read stuff from the file into the Student object Program.character.FirstName = inputStream.ReadLine(); Program.character.LastName = inputStream.ReadLine(); Program.character.Fighting = inputStream.ReadLine(); Program.character.Agility = inputStream.ReadLine(); Program.character.Reason = inputStream.ReadLine(); Program.character.Endurance = inputStream.ReadLine(); Program.character.Intuition = inputStream.ReadLine(); Program.character.Psyche = inputStream.ReadLine(); Program.character.Popularity = inputStream.ReadLine(); // cleanup inputStream.Close(); inputStream.Dispose(); } NextButton_Click(sender, e); } }
private void openToolStripButton_Click(object sender, EventArgs e) { // configuration for openFileDialog CharacterOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); CharacterOpenFileDialog.FileName = "Hero.txt"; CharacterOpenFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"; var result = CharacterOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { // open file stream to read using (StreamReader inputStream = new StreamReader( File.Open(CharacterOpenFileDialog.FileName, FileMode.Open))) { // read stuff from the file into the Student object heroNameChDataLabel.Text = inputStream.ReadLine(); NameChDataLabel.Text = inputStream.ReadLine(); fightingChDataLabel.Text = inputStream.ReadLine(); agilityChDataLabel.Text = inputStream.ReadLine(); strengthChDataLabel.Text = inputStream.ReadLine(); enduranceChDataLabel.Text = inputStream.ReadLine(); reasonChDataLabel.Text = inputStream.ReadLine(); intutionChDataLabel.Text = inputStream.ReadLine(); psycheChDataLabel.Text = inputStream.ReadLine(); popularityChDataLabel.Text = inputStream.ReadLine(); //cleanup inputStream.Close(); inputStream.Dispose(); } MainTabControl_SelectedIndexChanged(sender, e) } }
private void OpenButton_Click(object sender, EventArgs e) { CharacterOpenFileDialog.FileName = "Character.txt"; CharacterOpenFileDialog.InitialDirectory = "..//..//Data"; CharacterOpenFileDialog.ShowDialog(); }