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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to convert system.drawing.color to string and vice versa?

How to convert system.drawing.color to string and vice versa?

Scheduled Pinned Locked Moved Visual Basic
questiondatabasegraphicstutorial
3 Posts 2 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.
  • N Offline
    N Offline
    NetRams
    wrote on last edited by
    #1

    Hi, I need to store the controls backcolor in DB, and on reload, again i need to get color from DB and set as controls backcolor. How do i convert the system.drawing.color.green to string "Green" and vice versa. Any luck.

    Be simple and Be sample.

    N I 2 Replies Last reply
    0
    • N NetRams

      Hi, I need to store the controls backcolor in DB, and on reload, again i need to get color from DB and set as controls backcolor. How do i convert the system.drawing.color.green to string "Green" and vice versa. Any luck.

      Be simple and Be sample.

      N Offline
      N Offline
      NetRams
      wrote on last edited by
      #2

      Hey, Got the answer, I have done using the followin two functions to do that, Public Function GetColorToString(ByVal colorObj As System.Drawing.Color) As String Dim hexString As String hexString = "#" & Strings.Right("0" & Hex(colorObj.R), 2) & _ Strings.Right("0" & Hex(colorObj.G), 2) & _ Strings.Right("0" & Hex(colorObj.B), 2) Return hexString End Function Public Function GetColorFromString(ByVal strColor As String) As System.Drawing.Color If Not strColor Is Nothing Then Dim colConvert As New ColorConverter Return colConvert.ConvertFromString(strColor) End If End Function It's working for me.

      Be simple and Be sample.

      1 Reply Last reply
      0
      • N NetRams

        Hi, I need to store the controls backcolor in DB, and on reload, again i need to get color from DB and set as controls backcolor. How do i convert the system.drawing.color.green to string "Green" and vice versa. Any luck.

        Be simple and Be sample.

        I Offline
        I Offline
        IqbalVB
        wrote on last edited by
        #3

        Nah, don't waste time to write a function just get the control color and convert it to string. sub getcolorstr() dim color as string color = (control name).backcolor.tostring end sub that's done! :)

        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