|
||||||
| C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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: Code:
// Softwarekey is a connection to local_user in registry
Color tempColor = control.ForeColor;
softwareKey.SetValue("FontColor",tempColor.ToArgb());
Code:
Color tempColor = Color.FromArgb(Convert.ToInt32(softwareKey.GetValue("FontColor",Color.Gray)));
control.ForeColor = tempColor;
__________________
I Need Help |
| Sponsored Links |
|
|
|
|||
|
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?
__________________
I Need Help |
|
|||
|
Quote:
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?
__________________
I Need Help |
| Sponsored Links |
|
|
|
|||
|
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:\). |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| Xav | ........ | 1276.19 |
| MeTh0Dz|Reb0rn | ........ | 1048.58 |
| marwex89 | ........ | 869.98 |
| John | ........ | 868.39 |
| morefood2001 | ........ | 868.04 |
| WingedPanther | ........ | 761.06 |
| Brandon W | ........ | 684.87 |
| chili5 | ........ | 294.12 |
| Steve.L | ........ | 216.18 |
| dargueta | ........ | 192.86 |
Goal: 100,000 Posts
Complete: 81%