Got a nagging listbox questions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have tried everything I know, looked every where, and I still cannot figure out this
You see, I have a color stored in the registry and it shows up as say Color [red
and I cannot get that color out as Color.Red so that I can put it in a variable to be assigned to a label.backcolo
The registry getvalue code I use is as folllows

-----------------------------------------------------------------------------
PanelColors = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("My App"

Dim nameColor = PanelColors.GetValue("My App"

Label1.BackColor= nameColo
 
bobby j said:
I have tried everything I know, looked every where, and I still
cannot figure out this: You see, I have a color stored in the
registry and it shows up as say Color [red] and I cannot get that
color out as Color.Red so that I can put it in a variable to be
assigned to a label.backcolor The registry getvalue code I use is as
folllows:

-------------------------------------------------------------------------- ----
PanelColors = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("My
App")

Dim nameColor = PanelColors.GetValue("My App")

Label1.BackColor= nameColor

You should enable Option Strict first.
- The variable type is missing
- The type cast is missing
- You are trying to assign a String to a property expecting a Color object
-------------------------------------------------------------------------- ----------------
I get an error message saying "Specified cast is not valid"


You are storing the wrong string. The string is not parsable. You could use
System.Drawing.Color.ToKnownColor.ToString to convert a color object to a
string to store it in the registry, then use System.Drawing.Color.FromName
to convert it back from String to a Color object. Example:

Dim s As String
s = Color.Red.ToKnownColor.ToString
MsgBox(s)

s = "Blue"
Me.BackColor = Color.FromName(s)



--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
* "=?Utf-8?B?Ym9iYnkgag==?= said:
I have tried everything I know, looked every where, and I still cannot figure out this:
You see, I have a color stored in the registry and it shows up as say Color [red]
and I cannot get that color out as Color.Red so that I can put it in a variable to be assigned to a label.backcolor
The registry getvalue code I use is as folllows:

------------------------------------------------------------------------------
PanelColors = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("My App")

Dim nameColor = PanelColors.GetValue("My App")

Label1.BackColor= nameColor

I remember there was a similar topic some days ago:

\\\
Dim ColorName As String = ...
Me.Label1.BackColor = Color.FromKnownColor(DirectCast([Enum].Parse(GetType(KnownColor), ColorName), KnownColor))
///
 
Thank you guys
The both of you contributed to the solution
Armin, for his conversation
and Herfried, for his suggestion to pass HoldColor.Name instead of just HoldColor (from the previous post)
Once again, Thanks
I sure learned a lot
 
It's always a good idea to store colors as an RGB or ARGB value instead of
an actual name

bobby j said:
I have tried everything I know, looked every where, and I still cannot figure out this:
You see, I have a color stored in the registry and it shows up as say Color [red]
and I cannot get that color out as Color.Red so that I can put it in a
variable to be assigned to a label.backcolor
 
Back
Top