What is the correct way to save and restore colors from the registry? I need to save the forecolor and backcolor and this is currently what I have:
To Save:
To Restore:Code:// Softwarekey is a connection to local_user in registry Color tempColor = control.ForeColor; softwareKey.SetValue("FontColor",tempColor.ToArgb());
It doesn't seem to be the correct way but it is the only way I could come up with to do this. Any ideas?Code:Color tempColor = Color.FromArgb(Convert.ToInt32(softwareKey.GetValue("FontColor",Color.Gray))); control.ForeColor = tempColor;
I suppose you could binary serialize it, but I don't really see a problem with how you're doing it.
If you have multiple preferences, creating a serializable Preference class would probably be better. You could either binary serialize it and store in the registry or on disk, or XML serialize it to a config file. Or you could implement a custom "registry serializer" that would store it as meaningful names in the registry.
Other than that, I don't really see a problem with how you're doing it....
I have about 5-10 things that I save in the registry per form. There are about 5 forms.
I dont understand what binary serialization is. How does that work?
Is it still common to save settings into the registry or is XML used more?
Binary serialization basically just dumps the memory contents to a byte stream. You can then save that byte stream as a file on disk, or send it across the network, etc. Since it directly dumps memory, it doesn't have the same limitations as Xml serialization - but it's in a propietary format and isn't human readable.Originally Posted by NeedHelp
This seems to be a decent example of the basics.
I think the ".NET Way" is leaning more and more towards xml config files for user settings. I tend to use binary serialization for caches and persistent collections that I don't want the user messing with. Config files, OTOH, are useful in XML as it's (slightly) easier to comprehend and edit.
.NET 2.0 really steps up the built in config file support for both application settings and user settings. If you want to take advantage of this, here's a starting point on MSDN to read about the changes.
Thanks. I may switch to this. Currently I just store everything in the registry. Is binary serialization a good way to store register information?
IMO, not really. I'd say choose the registry or XML if you expect/want users/admins to muck with the settings. If you choose the registry, and then store it in binary, you kind of defeat that.
For settings you don't want to be edited outside of your code though, binary is good - but I'd just store it on disk. Just try to make it clear about what's a user setting and what's program data, and use the Windows/NET API functions for getting locations (so that your program works properly if, for instance, Windows isn't on C:\).
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks