|
-
Jun 15th, 2008, 12:12 AM
#1
Thread Starter
Member
[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
-
Jun 15th, 2008, 12:57 AM
#2
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?
-
Jun 15th, 2008, 01:54 AM
#3
Thread Starter
Member
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.
-
Jun 15th, 2008, 02:05 AM
#4
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.
-
Jun 15th, 2008, 02:12 AM
#5
Thread Starter
Member
Re: [RESOLVED] Color Palette Help
 Originally Posted by iPrank
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|