Results 1 to 7 of 7

Thread: [RESOLVED] Writing a forecolor value to a string

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2010
    Posts
    30

    Resolved [RESOLVED] Writing a forecolor value to a string

    Hey,

    I've set the colour of a label using the ColorDialog and I want to read the chosen colour value into a string, using the following code:

    Code:
    ColorDialog1.ShowDialog()
    label1.ForeColor = ColorDialog1.Color
    For example, I have chosen, say, blue as the colour.. How would I read this value into a string, or the hex code for this colour?

    Thanks in advance,

    PlaystationMasterBoy

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Writing a forecolor value to a string

    ColorDialog1.Color.Name

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2010
    Posts
    30

    Re: Writing a forecolor value to a string

    Fabulous. A*

    Thanks a lot.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2010
    Posts
    30

    Re: Writing a forecolor value to a string

    How would I then set the forecolor of a different control to equal that that I have written to the varialble. For example, I have written:

    Code:
    ColorDialog1.ShowDialog()
    label1.ForeColor = ColorDialog1.Color
    and...

    Code:
    colour1 = ColorDialog1.Color.Name
    How would I then set the forecolor of a different element to the same?

    I've tired..

    Code:
    Button9.ForeColor = colour1
    Thanks

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Writing a forecolor value to a string

    vb Code:
    1. Button9.ForeColor = color.fromname(colour1)

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2010
    Posts
    30

    Re: Writing a forecolor value to a string

    Quote Originally Posted by .paul. View Post
    vb Code:
    1. Button9.ForeColor = color.fromname(colour1)
    Thanks. That's a lifesaver.

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: [RESOLVED] Writing a forecolor value to a string

    it'd probably be easier to declare colour1 as color:

    vb Code:
    1. dim colour1 as color
    2. colour1 = ColorDialog1.Color
    3. ...
    4. Button9.ForeColor = colour1

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width