Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C# Programming

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

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.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-25-2006, 07:53 AM
NeedHelp NeedHelp is offline
Programming God
 
Join Date: May 2006
Posts: 527
Credits: 0
Rep Power: 12
NeedHelp is on a distinguished road
Default Proper way to store and retrieve colors from registry

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());
To Restore:
Code:
Color tempColor = Color.FromArgb(Convert.ToInt32(softwareKey.GetValue("FontColor",Color.Gray)));
control.ForeColor = tempColor;
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?
__________________
I Need Help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 05-25-2006, 01:38 PM
brackett brackett is offline
Programmer
 
Join Date: May 2006
Posts: 193
Credits: 0
Rep Power: 10
brackett is on a distinguished road
Default

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....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-25-2006, 05:31 PM
NeedHelp NeedHelp is offline
Programming God
 
Join Date: May 2006
Posts: 527
Credits: 0
Rep Power: 12
NeedHelp is on a distinguished road
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-26-2006, 10:08 AM
brackett brackett is offline
Programmer
 
Join Date: May 2006
Posts: 193
Credits: 0
Rep Power: 10
brackett is on a distinguished road
Default

Quote:
Originally Posted by NeedHelp
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.

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-28-2006, 08:31 AM
NeedHelp NeedHelp is offline
Programming God
 
Join Date: May 2006
Posts: 527
Credits: 0
Rep Power: 12
NeedHelp is on a distinguished road
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 05-28-2006, 10:28 PM
brackett brackett is offline
Programmer
 
Join Date: May 2006
Posts: 193
Credits: 0
Rep Power: 10
brackett is on a distinguished road
Default

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:\).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 11:36 PM.

Contest Stats

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

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 81%

Ads