Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C#] TextReader & StreamReader

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Sneak
Grandmaster Cheater Supreme
Reputation: 0

Joined: 05 Nov 2008
Posts: 1895

PostPosted: Sun Nov 22, 2009 8:20 pm    Post subject: [C#] TextReader & StreamReader Reply with quote

Well I would like to Write the info of Textbox1.text into a text file called Settings.txt, and then I want it to load the current Settings.txt into TextBox1 if I Press "Load". I got the Writing to the text file down, but not the reading of the file = textBox1.text.

Here is the whole code:

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace TextFileWriter
{
    public partial class Form1 : Form
    {
       
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            TextWriter tw = new StreamWriter("Settings.txt");
            tw.WriteLine(textBox1.Text);
            tw.Close();
           
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string Info = textBox1.Text;
            TextReader tr = new StreamReader("Settings.txt");
            Info = tr.ReadLine();
            tr.Close();
        }
    }
}


Button 1 = save
Button 2 = load


Thank you Very Happy

_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Nov 22, 2009 8:34 pm    Post subject: Reply with quote

you're never reading anything into the textbox, just the string you create.
Back to top
View user's profile Send private message
Henley
Grandmaster Cheater
Reputation: 0

Joined: 03 Oct 2006
Posts: 671

PostPosted: Mon Nov 23, 2009 3:09 am    Post subject: Reply with quote

Code:
            using (StreamReader sr = new StreamReader(Directory.GetCurrentDirectory() + "\\Settings.txt"))
            {
                String line;
                while ((line = sr.ReadLine()) != null)
                {
                    textBox1.Text += line + Environment.NewLine;
                }
            }
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites