?
Solved

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

Posted on 2008-11-11
7
Medium Priority
?
424 Views
Last Modified: 2013-11-27
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

0
Comment
Question by:Knightlite_James
  • 4
  • 3
7 Comments
 
LVL 11

Expert Comment

by:ladarling
ID: 22931138

If Not String.IsNullOrEmpty(CanvasColor) Then
Dim c As Color = Color.FromName(CanvasColor)
txt1.BackColor = c
End If
0
 

Author Comment

by:Knightlite_James
ID: 22931388
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
 
LVL 11

Expert Comment

by:ladarling
ID: 22931408
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 11

Accepted Solution

by:
ladarling earned 2000 total points
ID: 22931466
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
 

Author Comment

by:Knightlite_James
ID: 22931526
Hi,

That still did not work.  

Jim
0
 
LVL 11

Expert Comment

by:ladarling
ID: 22931657
What is the error?
0
 

Author Comment

by:Knightlite_James
ID: 22933285
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question