Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problems in converting colors

Problems in converting colors

Scheduled Pinned Locked Moved C#
windows-adminhelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AngryC
    wrote on last edited by
    #1

    Hi! I'm using the colorDialog to let the user select a color, then I save it to the registry. Everything is fine except with the user doesn't select a named color. What I am getting save to the registry is something like: ffff8000 I tried the following: ColorConverter colConvert = new ColorConverter(); treeview1.ForeColor = (Color)colConvert.ConvertFromString(regkey.GetValue("ColorName").ToString()); But it's not working when the color is not named, e.g. Yellow. I'm getting: ffff8000 is not a valid value for Int32. Please help. Thanks.

    C G 2 Replies Last reply
    0
    • A AngryC

      Hi! I'm using the colorDialog to let the user select a color, then I save it to the registry. Everything is fine except with the user doesn't select a named color. What I am getting save to the registry is something like: ffff8000 I tried the following: ColorConverter colConvert = new ColorConverter(); treeview1.ForeColor = (Color)colConvert.ConvertFromString(regkey.GetValue("ColorName").ToString()); But it's not working when the color is not named, e.g. Yellow. I'm getting: ffff8000 is not a valid value for Int32. Please help. Thanks.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      LOL - just answered you on MSDN. int decAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber); Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      1 Reply Last reply
      0
      • A AngryC

        Hi! I'm using the colorDialog to let the user select a color, then I save it to the registry. Everything is fine except with the user doesn't select a named color. What I am getting save to the registry is something like: ffff8000 I tried the following: ColorConverter colConvert = new ColorConverter(); treeview1.ForeColor = (Color)colConvert.ConvertFromString(regkey.GetValue("ColorName").ToString()); But it's not working when the color is not named, e.g. Yellow. I'm getting: ffff8000 is not a valid value for Int32. Please help. Thanks.

        G Offline
        G Offline
        Graham Nimbley
        wrote on last edited by
        #3

        Hi, There's nothing wrong with the code that you have posted. Just only a misunderstanding of what ColorConverter does. ColorConverter, as you probably have guessed, is only meant to convert a named color, as defined by a constant of Color, to it's Color instance equalivalent. To convert the hex representation you can use Color.FromArgb() Post back if there's anything you don't understand. :) Graham.

        G A 2 Replies Last reply
        0
        • G Graham Nimbley

          Hi, There's nothing wrong with the code that you have posted. Just only a misunderstanding of what ColorConverter does. ColorConverter, as you probably have guessed, is only meant to convert a named color, as defined by a constant of Color, to it's Color instance equalivalent. To convert the hex representation you can use Color.FromArgb() Post back if there's anything you don't understand. :) Graham.

          G Offline
          G Offline
          Graham Nimbley
          wrote on last edited by
          #4

          Just adding on to what Christian has answered: This should work. (I hope!)

          Color c=Color.FromArgb(int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber));

          [Edit] Yay! It works! :-D -- modified at 18:57 Sunday 18th June, 2006

          1 Reply Last reply
          0
          • G Graham Nimbley

            Hi, There's nothing wrong with the code that you have posted. Just only a misunderstanding of what ColorConverter does. ColorConverter, as you probably have guessed, is only meant to convert a named color, as defined by a constant of Color, to it's Color instance equalivalent. To convert the hex representation you can use Color.FromArgb() Post back if there's anything you don't understand. :) Graham.

            A Offline
            A Offline
            AngryC
            wrote on last edited by
            #5

            Thanks guys. It worked. :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups