Closed Thread
Results 1 to 6 of 6

Thread: Proper way to store and retrieve colors from registry

  1. #1
    NeedHelp Guest

    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?

  2. CODECALL Circuit advertisement

     
  3. #2
    brackett is offline Programmer
    Join Date
    May 2006
    Posts
    192
    Rep Power
    22
    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....

  4. #3
    NeedHelp Guest
    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?

  5. #4
    brackett is offline Programmer
    Join Date
    May 2006
    Posts
    192
    Rep Power
    22
    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.

  6. #5
    NeedHelp Guest
    Thanks. I may switch to this. Currently I just store everything in the registry. Is binary serialization a good way to store register information?

  7. #6
    brackett is offline Programmer
    Join Date
    May 2006
    Posts
    192
    Rep Power
    22
    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:\).

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Convert 256 colors to 16 colors - BMP Image
    By spyrytus in forum C and C++
    Replies: 9
    Last Post: 12-10-2009, 03:32 AM
  2. Replies: 4
    Last Post: 10-17-2009, 04:13 AM
  3. Proper iteration.
    By FakeRobotGymnast in forum C and C++
    Replies: 1
    Last Post: 01-18-2009, 07:37 PM
  4. Proper For Loops?
    By thieflock in forum Java Help
    Replies: 2
    Last Post: 11-13-2007, 12:04 PM
  5. Best place to store information in the registry
    By Void in forum General Programming
    Replies: 1
    Last Post: 06-26-2006, 03:44 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts