NOTE: I ORIGINALLY POSTED THIS ON DR
2nd NOTE: THIS IS THE MOST RELEVENT SECTION I COULD FIND. For this example, I will be showing an application I have already made for a friend in the past.
The language shown is C#, but this is applicable to many other languages.
(Sorry, the in-code comments are in German, but I'll translate them.)
[SIZE="2"][METHOD 1 - VISUAL STUDIO SETTINGS][/SIZE]
Translation: First we must start to string lists
Code
//Zuerst mussen wir zweite 'string lists' starten
public static List<string> ip = new List<string>();
public static List<string> name = new List<string>();
[SAVING VALUES]
We must set new setting values in the setting window.
At this window you must set the value name and the type.
Now, remember when I set that value of 'sample'?
We use the following to access it.
Translation: Recieve setting and a set a value
Code
Properties.Settings.Default.Sample = "Hello, World!"; //Bekomm settings und mach ein value
[SAVING ARRAYS / LISTS]
Many think this is hard, and well.. it is?
I'm here to guide you.
Remember, the ip and name lists we started earlier?
We will set all of the values in that list to a setting.
You must go back to the settings window and make a 'string collection'
Then you can assign to them with a foreach statement, like so:
Code
if (Properties.Settings.Default.IPS == null)
{
Properties.Settings.Default.IPS = new System.Collections.Specialized.StringCollection();
}
foreach (string ipz in ip)
{
Properties.Settings.Default.IPS.Add(ipz);
}
Simple enough, right? Now, they are there even when the application is closed!
Here's how we access them to put them back into our original lists.
Code
foreach (string namer in Properties.Settings.Default.NAMES)
{
name.Clear();
name.Add(namer);
}
Very simple! :P
Added (2009-07-16, 1:17 Am)
---------------------------------------------
[SIZE="2"][METHOD - 2 REGISTRY KEYS][/SIZE]
[NOTE: you need to reference Microsoft.Win32!]
We create a new subkey in HKEY_CURRENT_USER named: SavedData
Code
RegistryKey aKey = Registry.CurrentUser.CreateSubKey("SavedData");
Now, we need to save something!
This will create a value called: myText with the value of "Hello, World!".
Code
aKey.SetValue("myText", "Hello, World!");
Now what if we need to open these settings?
Code
RegistryKey aKey = Registry.CurrentUser.OpenSubKey("SavedData");
string getData = aKey.GetValue(Convert.ToString("myText"));
Easy enough, right?
Alright, the lesson is over kids, I know that I'm a bad teacher. But I was trying! :3
//END
Sorry for the double post, it wouldn't fit into one.