Results 1 to 5 of 5

Thread: commondialog colorpicker

  1. #1

    Thread Starter
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    I need to know how to get the RGB value from the color picker then use it in my application like
    RBG = commondialog1.color
    then RBG would equal something like 255 127 67 or any RGB value a person picks in the color picker. THANKS

    ------------------
    DiGiTaIErRoR

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Try:
    Code:
    Private Sub Command1_Click()
        On Error GoTo ColorErr
        With CommonDialog1
            .CancelError = True
            .ShowColor
            BackColor = .Color
            Caption = GetRGB(.Color)
        End With
    ColorErr:
    End Sub
    
    Private Function GetRGB(ByVal lColor As Long, Optional ByVal iPigment As Integer = 3) As String
        Dim sCol As String
        sCol = Right$("000000" & Hex$(lColor), 6)
        If iPigment > 2 Then
            GetRGB = "R:" & Right$(sCol, 2) & " G:" & Mid$(sCol, 3, 2) & " B:" & Left$(sCol, 2)
        Else
            GetRGB = Mid$(sCol, 5 - (iPigment * 2), 2)
        End If
    End Function
    By passing GetRGB no Additional Parameter for iPigment it will Return the RGB Values in Hex Format.
    To get the Value of a particular element, pass it's index, eg.

    iRed = Val("&H" & GetRGB(.Color, 0))

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3

    Thread Starter
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    Okay ummm... I'm still getting weird numbers can you just tell me how to get the RBG one space inbetween each "255 255 255" if I choose white I really don't get this stuff.
    I don't get ne code unless I write I usually.
    thanks Aaron

    ------------------
    DiGiTaIErRoR

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    The Function I posted returns the Hexidecimal Value of Each Element of the Color (RGB), to Convert this to a Decimal Value use Val("&H" & HexValue), eg.

    sWhite = Val("&H" & GetRGB(vbWhite, 0)) & " " & Val("&H" & GetRGB(vbWhite, 1)) & " " & Val("&H" & GetRGB(vbWhite, 2))

    This would assign "255 255 255" to sWhite.

    If all you're interested in is the Decimal Value, then Modify the Function to Convert the Hex Before Returning the Value, eg.
    Code:
    Private Function GetRGB(ByVal lColor As Long, Optional ByVal iPigment As Integer = 3) As String
        Dim sCol As String
        sCol = Right$("000000" & Hex$(lColor), 6)
        If iPigment > 2 Then
            GetRGB = Val("&H" & Right$(sCol, 2)) & " " & Val("&H" & Mid$(sCol, 3, 2)) & " " & Val("&H" & Left$(sCol, 2))
        Else
            GetRGB = Val("&H" & Mid$(sCol, 5 - (iPigment * 2), 2))
        End If
    End Function
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  5. #5

    Thread Starter
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    Ok this is what i have to do i have a program it assigns RGB from colorsel of commondialog to a textbox
    like commondialog.selcolor needs to be converted to RBG value all three to match it and then put it in a text window

    ------------------
    DiGiTaIErRoR

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