|
-
Dec 1st, 1999, 07:28 AM
#1
Thread Starter
So Unbanned
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
-
Dec 1st, 1999, 10:23 AM
#2
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]
-
Dec 1st, 1999, 10:38 AM
#3
Thread Starter
So Unbanned
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
-
Dec 1st, 1999, 12:12 PM
#4
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]
-
Dec 1st, 1999, 12:39 PM
#5
Thread Starter
So Unbanned
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|