Main | Registration | Login Welcome Guest | RSS
Vote for RawrGunz!Please VOTE for RawrGunz at top 200 pserver list!
[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Forum moderator: Splash, ManyBlackPpl  
[CODING][TUT] Saving Settings with sets and Registry Keys
xVengeanceDate: Thursday, 2009-07-16, 0:17 AM | Message # 1
RawrGunz Beginner
Group: Users
Messages: 79
Reputation: 6
Status: Offline
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.) smile

[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. wink

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.


Check this out. :P
http://rawrgaming.ucoz.com/forum/16-745-1


Message edited by xVengeance - Thursday, 2009-07-16, 0:17 AM
 
YoshinoDate: Thursday, 2009-07-16, 1:24 AM | Message # 2
Trial Game Mod
Group: Moderators
Messages: 1151
Reputation: 18
Status: Offline
Teach me via msn pl0x? :D




Message edited by Yoshino - Thursday, 2009-07-16, 1:24 AM
 
xVengeanceDate: Thursday, 2009-07-16, 1:27 AM | Message # 3
RawrGunz Beginner
Group: Users
Messages: 79
Reputation: 6
Status: Offline
LOL.
Have a spare few months?


Check this out. :P
http://rawrgaming.ucoz.com/forum/16-745-1
 
YoshinoDate: Thursday, 2009-07-16, 1:28 AM | Message # 4
Trial Game Mod
Group: Moderators
Messages: 1151
Reputation: 18
Status: Offline
Quote (xVengeance)
Have a spare few months?

Yesh, although instead of few (3-4) I think it will be some (4-6) :P



 
xVengeanceDate: Thursday, 2009-07-16, 1:30 AM | Message # 5
RawrGunz Beginner
Group: Users
Messages: 79
Reputation: 6
Status: Offline
Learn Here

Muwaha.


Check this out. :P
http://rawrgaming.ucoz.com/forum/16-745-1
 
YoshinoDate: Thursday, 2009-07-16, 1:35 AM | Message # 6
Trial Game Mod
Group: Moderators
Messages: 1151
Reputation: 18
Status: Offline
Quote (xVengeance)

Learn Here

Muwaha.

-sighs-
I fail at learning independently on things such as this. (Ask black ;D)



 
MojoDate: Thursday, 2009-07-16, 2:48 AM | Message # 7
RawrGunz Owner
Group: Administrators
Messages: 477
Reputation: 63
Status: Offline
nice nice tut :P


 
  • Page 1 of 1
  • 1
Search:

Copyright RawrGunz © 2025
Powered by uCoz