| View previous topic :: View next topic |
| Author |
Message |
yoyonerd Grandmaster Cheater
Reputation: 0
Joined: 26 Apr 2008 Posts: 699 Location: -->formerly yoyonerd<--
|
Posted: Sun Nov 02, 2008 7:35 pm Post subject: [C#]How to save settings? |
|
|
How can I save application settings?
I heard about .ini and .xml, i've also heard using the .settings built into .net which i heard creates an .xml for you
I would like to know maybe how i could do a couple of things:
save which of 2 radiobuttons was checked as the form was closing, and how to read WHICH button was last checked, and check it during run-time
how i could save the text of 2 different textboxes during closing, and upon runtime have the same text remain
i've saved text to like a .txt, but i can't seem to figure out how i can like "label" controls and such
i hope i made sense _________________
|
|
| Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Sun Nov 02, 2008 8:11 pm Post subject: |
|
|
You can use the registry, ini file, or xml file.
There are examples on all over the internet. I prefer to use the registry. _________________
Blog
| Quote: | Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that |
|
|
| Back to top |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Sun Nov 02, 2008 8:42 pm Post subject: |
|
|
you dont have to use INI Files in particular.
The main concept, is to write your information to a Text File.
Then to load it, read the file line by line and compare strings  |
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Sun Nov 02, 2008 9:00 pm Post subject: |
|
|
If there are lots of things to save, I like to use a database file, (mdb) to store them. If it is a few things, make a filestream and save to a .ini or .txt file. _________________
|
|
| Back to top |
|
 |
deleted19776 I post too much
Reputation: 11
Joined: 29 Apr 2007 Posts: 3838
|
Posted: Sun Nov 02, 2008 9:37 pm Post subject: |
|
|
| I personally would prefer the registry, since even if you delete the files, the settings are still there. |
|
| Back to top |
|
 |
Anden100 Grandmaster Cheater
Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Mon Nov 03, 2008 2:01 am Post subject: |
|
|
| If you decide to use registry, remember that you can always delete/modify the info you made in the registry using "Start>run>regedit" |
|
| Back to top |
|
 |
Spawnfestis GO Moderator
Reputation: 0
Joined: 02 Nov 2007 Posts: 1746 Location: Pakistan
|
Posted: Mon Nov 03, 2008 10:50 am Post subject: |
|
|
and how to read WHICH button was last checked
PSEUDO CODE:
| Code: | | if radiobutton1 = true then save radiobutton1 else if radiobutton = true save radiobutton2 |
Doesn't have to be more complicated than that.
I recommend you to use XML with C#. _________________
CLICK TO HAX MAPLESTORAY ^ !!!! |
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Mon Nov 03, 2008 1:45 pm Post subject: |
|
|
It depends on what you want:
If users see an ini file in the folder of your program, they might edit it. If you don't want them to edit it, you might want to use the registry. (It's still possible to edit it off course, but harder for most people) |
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Tue Nov 04, 2008 4:48 pm Post subject: |
|
|
| Spawnfestis wrote: | and how to read WHICH button was last checked
PSEUDO CODE:
| Code: | | if radiobutton1 = true then save radiobutton1 else if radiobutton = true save radiobutton2 |
Doesn't have to be more complicated than that.
I recommend you to use XML with C#. |
Real code:
| Code: |
StreamWriter sw = new StreamWriter("settings.xml");
if (rdbOne.Checked)
{
XMLWrite("SelectedRDB", "rdbOne");
}
else if (rdbTwo.Checked)
{
XMLWrite("SelectedRDB", "rdbTwo");
}
else
{
MessageBox.Show("wtf?");
}
...
private void XMLWrite(StreamWriter sw, string Node, string Value)
{
StringBuilder sb = new StringBuilder();
sb.Append("<").Append(Node).AppendLine(">").Append(" ").AppendLine(Value).Append("</").Append(Node).Append(">");
sw.Write(sb.ToString());
}
|
_________________
|
|
| Back to top |
|
 |
Dylanwade How do I cheat?
Reputation: 0
Joined: 21 Feb 2009 Posts: 0 Location: Hacking Gaia
|
Posted: Tue Nov 04, 2008 6:33 pm Post subject: |
|
|
| I save mine into an .ini file, registry is good too. |
|
| Back to top |
|
 |
yoyonerd Grandmaster Cheater
Reputation: 0
Joined: 26 Apr 2008 Posts: 699 Location: -->formerly yoyonerd<--
|
Posted: Wed Nov 05, 2008 5:27 pm Post subject: |
|
|
on vista, would editing registry need admin permission? _________________
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Wed Nov 05, 2008 6:18 pm Post subject: |
|
|
| yoyonerd wrote: | | on vista, would editing registry need admin permission? |
I think XP would require it too. _________________
|
|
| Back to top |
|
 |
Habufe Expert Cheater
Reputation: 0
Joined: 03 Sep 2007 Posts: 149 Location: http://www.SaviourFagFails.com/
|
Posted: Thu Nov 06, 2008 10:31 am Post subject: |
|
|
if you are inexperienced with this, you would probably like the registry method. its very organized, easy to use and user friendly.
and about the administrator question, you only need to be admin if you are writing into protected area (i think this includes all areas other then hkey current user) |
|
| Back to top |
|
 |
ElJEffro Grandmaster Cheater Supreme
Reputation: 0
Joined: 15 Apr 2007 Posts: 1881 Location: La Tierra
|
Posted: Fri Nov 07, 2008 2:14 am Post subject: |
|
|
| Code: | List<string> allLines = new List<string>();
using (StreamReader reader = new StreamReader("whatever.ini"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
allLines.Add(line);
}
}
|
to get numerical data, ill use this example of a .ini
| Code: | [data]
number1=42
number2=69
|
now to convert it to a format you can use
| Code: |
foreach (string line in allLines)
{
if ( line.StartsWith("number") ) // it is numerical data
{
int data;
if (!Int32.TryParse( line.Split('=')[1], out data)
MessageBox.Show("Invalid integer read from file");
}
} |
|
|
| Back to top |
|
 |
|