How Do I Save and Retrieve A Color From The Registry?

Hi,

I am trying to save and retrieve a color from the registry so that when the user selects a textbox color, the same color will appear when the user starts the program

The code I used to write the registry is shown below.

How do I retrieve the color back from the registry and assign it to the Textbox?

The code I have listed below gets an error:

Value of type 'String' cannot be converted to 'System.Drawing.Color'.

This is the same type of error I had with an earlier post:

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23879548.html

Can anyone tell me the correct code, so I can retrieve the color name?

Your help would be greatly appreciated.

Jim


'Code to write to registry
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Knightlite\Signal 102 V5\Registration\CanvasColor", "Canvas", ColorDialog1.Color)
 
'To retrieve color, I use:
 
 Dim CanvasColor As String = CStr(My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Knightlite\Signal 102 V5\Registration\CanvasName", "Canvas", String.Empty))
 
txt1.BackColor = CanvasColor

Open in new window

Knightlite_JamesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ladarlingCommented:

If Not String.IsNullOrEmpty(CanvasColor) Then
Dim c As Color = Color.FromName(CanvasColor)
txt1.BackColor = c
End If
0
Knightlite_JamesAuthor Commented:
Hi ladarling,

Thank you for taking the time to try to help me. I ran the code listed below and it still did not work.

Any idea what may be wrong?

Jim
Dim CanvasColor As String = CStr(My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Knightlite\Signal 102 V5\Registration\CanvasName", "Canvas", String.Empty))
 
        If Not String.IsNullOrEmpty(CanvasColor) Then
            Dim c As Color = Color.FromName(CanvasColor)
            txt1.BackColor = c
 
        End If

Open in new window

0
ladarlingCommented:
I would also add, though, that you dont have to use the registry to store that information unless you just want to. The application settings addition lets you store strongly typed user setting data (like Color objects) in your application. You can then use, modify, and save settings using the My.Settings namespace.
http://msdn.microsoft.com/en-us/library/cftf714c(VS.80).aspx
 You may already know all this and still want to use the registry, I just thought I would point it out :-)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ladarlingCommented:
Sorry about that, you need to save the name of the color to the registry, in my example:
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Knightlite\Signal 102 V5\Registration\CanvasColor", "Canvas", ColorDialog1.Color.Name)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Knightlite_JamesAuthor Commented:
Hi,

That still did not work.  

Jim
0
ladarlingCommented:
What is the error?
0
Knightlite_JamesAuthor Commented:
It does not give an error.  The color saves to the registry, but when you try to load it back from the registry, you jest get the white textbox rather than the color.

Jim
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.