Re: Got a nagging listbox questions

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Armin Zingler (az.nospam_at_freenet.de)
Date: 05/01/04


Date: Sat, 1 May 2004 02:01:50 +0200


"bobby j" <anonymous@discussions.microsoft.com> schrieb
> 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


Relevant Pages

  • Re: How to get the Color value from SystemColors
    ... You can use Color.FromNameto get the Color object associated ... with that system color. ... to extract a Color from a string. ... RequestedServer in the page that contains the control that this code is ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: working with a string from a textbox
    ... Then use Color.FromName to get a color object ... > really had to manipulate a string before. ... > string to assign the colors to three boxes? ...
    (microsoft.public.dotnet.languages.vb)
  • Problems Managing Required Field and Form Events
    ... Dim CheckVal As String ... If CheckVal = "Missing" Then ... Private Sub Form_BeforeUpdate ... Do you want to close the database object anyway? ...
    (microsoft.public.access.formscoding)
  • Problems Managing Required Field and Form Events
    ... Dim CheckVal As String ... If CheckVal = "Missing" Then ... Private Sub Form_BeforeUpdate ... Do you want to close the database object anyway? ...
    (microsoft.public.access.formscoding)
  • RE: dictionary/hash and 1 versus 1
    ... In order to keep things simple, Perl's string operators ... programming language you have to use its idioms or you end up fighting ... type cast the data: a + b ... and cluttered code is harder to understand ...
    (comp.lang.python)