Results 1 to 5 of 5

Thread: [RESOLVED] Color Palette Help

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    36

    Resolved [RESOLVED] Color Palette Help

    I have a button in my form that opens a color palette using the CommonDialog component. I was wondering if there is a way to set the hex decimal of the color that is chosen in the palette to a label.

    For example, if someone chooses the color red in the color palette, then

    Label1's caption would be #FFOOOO

  2. #2
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Color Palette Help

    Here's one way you could do it:
    Code:
    Private Sub Command1_Click()
      Dim lngColor As Long
      Dim lngRed As Long
      Dim lngGreen As Long
      Dim lngBlue As Long
      Dim strHex As String
      
      CommonDialog1.ShowColor
      lngColor = CommonDialog1.Color
      lngRed = (lngColor And vbRed)
      lngGreen = (lngColor And vbGreen) \ &H100&
      lngBlue = (lngColor And vbBlue) \ &H10000
      
      strHex = "#"
      If lngRed < 16 Then strHex = strHex & "0"
      strHex = strHex & Hex(lngRed)
      If lngGreen < 16 Then strHex = strHex & "0"
      strHex = strHex & Hex(lngGreen)
      If lngBlue < 16 Then strHex = strHex & "0"
      strHex = strHex & Hex(lngBlue)
      Label1.Caption = strHex
    End Sub
    Any questions?

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    36

    Re: Color Palette Help

    Thanks that worked!

    Edit: I do have 1 question, is there a way to have the caption have no # and just the number?
    Last edited by mike 92; Jun 15th, 2008 at 02:03 AM.

  4. #4
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: [RESOLVED] Color Palette Help

    http://www.devx.com/vb2themax/Tip/19166

    Edit: Don't add the "#" string at the beginning of strHex (post#2) or in ColorToHTML()'s return value (linked code).
    Last edited by iPrank; Jun 15th, 2008 at 02:11 AM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    36

    Re: [RESOLVED] Color Palette Help

    Quote Originally Posted by iPrank
    http://www.devx.com/vb2themax/Tip/19166

    Edit: Don't add the "#" string at the beginning of strHex (post#2) or in ColorToHTML()'s return value (linked code).
    Okay thanks

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