CabConModding
Facebook
Twitter
youtube
Discord
Contact us
RSS
Menu
CabConModding
Home
New
Top
Premium
Rules
FAQ - Frequently Asked Questions
Games
Fornite
Call of Duty: Black Ops 3
Clash of Clans
Grand Theft Auto 5
Apex Legends
Assassin’s Creed Origins
Forums
Premium
Latest posts
What's new
Latest posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Log in
Register
What's new
Premium
Latest posts
Menu
Log in
Register
Navigation
Install the app
Install
More options
Dark Theme
Contact us
Close Menu
Forums
Tech Boards
Computer Programming
Source Code & Tutorial
[C#] Saving a Config Tutorial (Reading & Writing to Text)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Harry" data-source="post: 13346" data-attributes="member: 35"><p>Hey CCM,</p><p>Haven't made a thread in a while ey??</p><p>Today I'm making a <strong>very</strong> simple code. Most users should be able to do this, but time and time again I see tools that could easy implement this useful function, but don't.</p><p>So you can use this for a lot of things, such as:</p><p>Saving Login Credentials (You may want to make an Encryption script and Decryption Script for this)</p><p>Saving Program Config (EG: Colour, Themes, Fonts, Size, Checkboxes/Radiobuttons selected?!)</p><p>& anything you can see yourself using this for. Now, lets get into it!</p><p></p><p>First, make a new Form on VS (I'll be using VS 2010). For the sake of this tutorial, my Project is going to be called 'Tutorial'</p><p>Setup the Form's Setting how you like (or you can implement this into a pre-made form)</p><p>Make something you want to save. For me, this is going to be background colour. Ill be making 4 RadioButtons with 4 Different colours for me to save to a BackgroundConfig.txt (the .txt can be nearly ANYTHING you want it to be, eg: .CCM, .PFM, .Harry, .AllahuAkbar, etc. It is just reading & writing to it in plain text.</p><p></p><p><img src="http://i.imgur.com/xcia3mT.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /></p><p>Now lets make a new timer and double click on it so we can dive into the code <img src="/styles/default/xenforo/smilies.emoji/people/slight_smile.emoji.svg" class="smilie" loading="lazy" alt=":smile:" title="Smile :smile:" data-shortname=":smile:" /></p><p>You want to paste this script (This will make it so you can actually write to the file)</p><p>[CODE]private void timer1_Tick(object sender, EventArgs e)</p><p> {</p><p> if (radioButton1.Checked == true)</p><p> {</p><p> System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\Config.txt", "Colour = Crimson");</p><p> this.BackColor = System.Drawing.Color.Crimson;</p><p> }</p><p> else</p><p> if (radioButton2.Checked == true)</p><p> {</p><p> System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\Config.txt", "Colour = Cyan");</p><p> this.BackColor = System.Drawing.Color.Cyan;</p><p> }</p><p> else</p><p> if (radioButton3.Checked == true)</p><p> {</p><p> System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\Config.txt", "Colour = Lime");</p><p> this.BackColor = System.Drawing.Color.Lime;</p><p> }</p><p> else</p><p> if (radioButton4.Checked == true)</p><p> {</p><p> System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\Config.txt", "Colour = Yellow");</p><p> this.BackColor = System.Drawing.Color.Yellow;</p><p> }</p><p> }[/CODE]</p><p></p><p>Ok. So you may want to edit this code ey?</p><p>Look at this code:</p><p>[Spoiler]System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\Config.txt", "Colour = Lime");[/spoiler]</p><p>There are a few things you can change here. </p><p>"Colour = Lime" is what will be written to the file. This is also what we will be reading later in the tutorial.</p><p>"@"C:\Users\Public\TestFolder\Config.txt"" is where its going to be written. </p><p>Think <strong>carefully </strong>when changing this. Remember that a lot of people aren't going to have:</p><p>"C:\Users\<Your Name>" because their PC is going to be named something differently. If you aren't going to release this, don't worry, but if you are, you are going to need to choose a spot that everyone has. You can find things like the Programs directory online to write to (I don't have it right now)</p><p></p><p>Now, add this whole script somewhere in your code:</p><p>[CODE]void ColourOnLoad()</p><p> {</p><p> string text = System.IO.File.ReadAllText(@"C:\Users\Public\TestFolder\Config.txt");</p><p> if(text == "Colour = Crimson")</p><p> {</p><p> this.BackColor = System.Drawing.Color.Crimson;</p><p> radioButton1.Checked = true;</p><p> }</p><p> else</p><p> if (text == "Colour = Cyan")</p><p> {</p><p> this.BackColor = System.Drawing.Color.Cyan;</p><p> radioButton2.Checked = true;</p><p> }</p><p> else</p><p> if (text == "Colour = Lime")</p><p> {</p><p> this.BackColor = System.Drawing.Color.Lime;</p><p> radioButton3.Checked = true;</p><p> }</p><p> else</p><p> if (text == "Colour = Yellow")</p><p> {</p><p> this.BackColor = System.Drawing.Color.Yellow;</p><p> radioButton4.Checked = true;</p><p> }</p><p> else</p><p> if (text == "" || text == " ")</p><p> {</p><p> MessageBox.Show("Config is broken", "Tool Name");</p><p> }</p><p> }[/CODE]</p><p>Double Click on the form and paste this:</p><p>[CODE]ColourOnLoad();</p><p> timer1.Start();[/CODE]</p><p></p><p>and now your good to go <img src="/styles/default/xenforo/smilies.emoji/people/slight_smile.emoji.svg" class="smilie" loading="lazy" alt=":smile:" title="Smile :smile:" data-shortname=":smile:" /></p><p></p><p>Post questions below!</p><p></p><p>Now the only thing you need to remember, is your need to make the Config file itself and place it there <img src="/styles/default/xenforo/smilies.emoji/people/slight_smile.emoji.svg" class="smilie" loading="lazy" alt=":smile:" title="Smile :smile:" data-shortname=":smile:" /></p><p></p><p>Have fun. You can edit this script to change and run anything you want.</p><p></p><p>~ Harry</p></blockquote><p></p>
[QUOTE="Harry, post: 13346, member: 35"] Hey CCM, Haven't made a thread in a while ey?? Today I'm making a [B]very[/B] simple code. Most users should be able to do this, but time and time again I see tools that could easy implement this useful function, but don't. So you can use this for a lot of things, such as: Saving Login Credentials (You may want to make an Encryption script and Decryption Script for this) Saving Program Config (EG: Colour, Themes, Fonts, Size, Checkboxes/Radiobuttons selected?!) & anything you can see yourself using this for. Now, lets get into it! First, make a new Form on VS (I'll be using VS 2010). For the sake of this tutorial, my Project is going to be called 'Tutorial' Setup the Form's Setting how you like (or you can implement this into a pre-made form) Make something you want to save. For me, this is going to be background colour. Ill be making 4 RadioButtons with 4 Different colours for me to save to a BackgroundConfig.txt (the .txt can be nearly ANYTHING you want it to be, eg: .CCM, .PFM, .Harry, .AllahuAkbar, etc. It is just reading & writing to it in plain text. [img]http://i.imgur.com/xcia3mT.png[/img] Now lets make a new timer and double click on it so we can dive into the code :) You want to paste this script (This will make it so you can actually write to the file) [CODE]private void timer1_Tick(object sender, EventArgs e) { if (radioButton1.Checked == true) { System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\Config.txt", "Colour = Crimson"); this.BackColor = System.Drawing.Color.Crimson; } else if (radioButton2.Checked == true) { System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\Config.txt", "Colour = Cyan"); this.BackColor = System.Drawing.Color.Cyan; } else if (radioButton3.Checked == true) { System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\Config.txt", "Colour = Lime"); this.BackColor = System.Drawing.Color.Lime; } else if (radioButton4.Checked == true) { System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\Config.txt", "Colour = Yellow"); this.BackColor = System.Drawing.Color.Yellow; } }[/CODE] Ok. So you may want to edit this code ey? Look at this code: [Spoiler]System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\Config.txt", "Colour = Lime");[/spoiler] There are a few things you can change here. "Colour = Lime" is what will be written to the file. This is also what we will be reading later in the tutorial. "@"C:\Users\Public\TestFolder\Config.txt"" is where its going to be written. Think [B]carefully [/B]when changing this. Remember that a lot of people aren't going to have: "C:\Users\<Your Name>" because their PC is going to be named something differently. If you aren't going to release this, don't worry, but if you are, you are going to need to choose a spot that everyone has. You can find things like the Programs directory online to write to (I don't have it right now) Now, add this whole script somewhere in your code: [CODE]void ColourOnLoad() { string text = System.IO.File.ReadAllText(@"C:\Users\Public\TestFolder\Config.txt"); if(text == "Colour = Crimson") { this.BackColor = System.Drawing.Color.Crimson; radioButton1.Checked = true; } else if (text == "Colour = Cyan") { this.BackColor = System.Drawing.Color.Cyan; radioButton2.Checked = true; } else if (text == "Colour = Lime") { this.BackColor = System.Drawing.Color.Lime; radioButton3.Checked = true; } else if (text == "Colour = Yellow") { this.BackColor = System.Drawing.Color.Yellow; radioButton4.Checked = true; } else if (text == "" || text == " ") { MessageBox.Show("Config is broken", "Tool Name"); } }[/CODE] Double Click on the form and paste this: [CODE]ColourOnLoad(); timer1.Start();[/CODE] and now your good to go :) Post questions below! Now the only thing you need to remember, is your need to make the Config file itself and place it there :) Have fun. You can edit this script to change and run anything you want. ~ Harry [/QUOTE]
Verification
Post reply
Forums
Tech Boards
Computer Programming
Source Code & Tutorial
[C#] Saving a Config Tutorial (Reading & Writing to Text)
CabConModding is now on facebook! Check the latest Updates, the Site Status and much more now!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top