Click to See Complete Forum and Search --> : commondialog colorpicker
DiGiTaIErRoR
Dec 1st, 1999, 06:28 AM
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
Aaron Young
Dec 1st, 1999, 09:23 AM
Try:
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
aarony@redwingsoftware.com
adyoung@win.bright.net
DiGiTaIErRoR
Dec 1st, 1999, 09:38 AM
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
Aaron Young
Dec 1st, 1999, 11:12 AM
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.
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
aarony@redwingsoftware.com
adyoung@win.bright.net
DiGiTaIErRoR
Dec 1st, 1999, 11:39 AM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.