|
-
Aug 2nd, 2008, 06:18 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Color Picker Control... :P
Ok so...(mm i think i use triple point too much xD) i'm making a simple color picker control for my App and i have 2 questions:
1) Since i couldn't write my own Hex2RGB function due to many errors :P (i tried using CByte() but couldn't get it to work properly)
so i found this code:
Code:
Public Function HEXCOL2RGB(ByVal HexColor As String) As String
'The input at this point could be HexColor = "#00FF1F"
Dim Red As String
Dim Green As String
Dim Blue As String
HexColor = Replace(HexColor, "#", "")
'Here HexColor = "00FF1F"
Red = Val("&H" & Mid(HexColor, 1, 2))
'The red value is now the long version of "00"
Green = Val("&H" & Mid(HexColor, 3, 2))
'The red value is now the long version of "FF"
Blue = Val("&H" & Mid(HexColor, 5, 2))
'The red value is now the long version of "1F"
HEXCOL2RGB = RGB(Red, Green, Blue)
'The output is an RGB value
End Function
But the problem is that it adds a # to it and i don't want it to do so... i tried removing some parts of the code... but *****s up* the function.
Can anyone help me on this or provide me with a better function??
2) My app has xp styles "installed" on it but if i make a control... when i use it will it take the style? or do i have to do something like the things you do to the application itself?
Thx in advance!!
REMEMBER if i've been useful RATE me plz 
-
Aug 2nd, 2008, 07:26 AM
#2
Re: Color Picker Control... :P
Here's something
Code:
Public Function HEXCOL2RGB(ByVal sHexColor As String) As Long
Dim TmpDbl As Double, TmpLng As Long
HEXCOL2RGB = -1 'this indicates a fail
sHexColor = UCase$(Trim$(sHexColor)) 'remove spaces and force case
If Left$(sHexColor, 2) <> "&H" Then sHexColor = "&H" & sHexColor 'Add Hex prefix if needed
If IsNumeric(sHexColor) Then 'Can be coerced to a number
TmpDbl = CDbl(sHexColor) 'Using double to avoid overflow
Select Case TmpDbl
Case Is < 0 'out of range, skip
Case Is < &H1000000 'in the range 0-&hffffff
TmpLng = TmpDbl
'Convert from BigEndian to LittleEndian
HEXCOL2RGB = (TmpLng And &HFF&) * &H10000 Or (TmpLng \ &H10000) Or (TmpLng And &HFF00&)
End Select
End If
End Function
It's a little more robust than your function in how it checks the string the following would be valid input.
" 123456 "
"&h8080ff"
" AbCdEf "
It also returns a long rather than a string. If the input is invalid (not a number or out of range) the return is -1
Edit: by the way, the common dialogue control has a colour picker built in
Last edited by Milk; Aug 2nd, 2008 at 07:45 AM.
-
Aug 2nd, 2008, 08:18 AM
#3
Thread Starter
Addicted Member
Re: Color Picker Control... :P
Edit: by the way, the common dialogue control has a colour picker built in
I know it has but i prefer mine :P
Well it wasn't my function... i just found it as i said...
And how would i go about putting the results on three text boxes 1 for red m 1 for green and 1 for blue??
Thx in advance!
REMEMBER if i've been useful RATE me plz 
-
Aug 2nd, 2008, 08:56 AM
#4
Re: Color Picker Control... :P
Code:
Public Sub SplitColour(Colour As Long, Red As Byte, Green As Byte, Blue As Byte)
Red = Colour And &HFF&
Green = (Colour \ &H100&) And &HFF&
Blue = (Colour \ &H10000) And &HFF&
End Sub
-
Aug 2nd, 2008, 09:44 AM
#5
Thread Starter
Addicted Member
Re: Color Picker Control... :P
i can't get it to work 
can u try it and reupload if u success pls??
here is my project...
Thx m8!
Last edited by VB<3er; Aug 2nd, 2008 at 11:20 AM.
REMEMBER if i've been useful RATE me plz 
-
Aug 2nd, 2008, 10:14 AM
#6
Re: Color Picker Control... :P
Because it requires the return of three values I made it a sub, you would use it like this...
Code:
Dim Red As Byte, Green As Byte, Blue As Byte
SplitColour 12648200, Red, Green, Blue
Debug.Print Red, Green, Blue
Alternatively you could define a UDT of three bytes and make it a function which returns the UDT
-
Aug 2nd, 2008, 11:34 AM
#7
Re: Color Picker Control... :P
The built in ColorPicker control doesnt work for you in your situation?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 2nd, 2008, 11:57 AM
#8
Thread Starter
Addicted Member
Re: Color Picker Control... :P
Yes it works robdog but i wanted to use mine 
@Milk!
Thx man worked perfect!!
Really thx!
REMEMBER if i've been useful RATE me plz 
-
Aug 2nd, 2008, 11:59 AM
#9
Re: [RESOLVED] Color Picker Control... :P
Ok np. I just wasnt sure if you knew about it as it can be shown in advanced more to open the right side and expose the color picker spectrum. also you can load the custom colors boxes with your own colors.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
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
|