I need to set some table cells which I am adding from code.
I am using;
cell.backcolor = cell.backcolor.white
for example to set it to white - this is all very well and good for a
'named' colour - but how do I set this for #d4c5db as an example? I have
many colours which I need to enter the HTML hash number for rather than a
named color.
I looked at the RGB, but I dont *think* that will work completely as I'm
using colours which are not always in the 256 colour range, I just I'd also
have to set the saturation, brightness and hue, but I am unsure what to
enter for these as:
cell.backcolor.getsaturation
for example - has a type of 'single' I have no idea what this is, it doesnt
seem to allow me to say = 210 or (210)...
Any help would be appreciated, I guess I was hoping that I could just have
something like:
cell.backcolor = cell.backcolor(#d4c5db)
which would have been nice!
Regards
RobOk - so I realised that the html colors are hex, and that if I convert the
hex to dec I can then do what I want...so...
I made the following function:
Function HexToDec(ByVal Hex As String) As Color
' Declare variables
Dim strHexRed As String
Dim strHexGreen As String
Dim strHexBlue As String
Dim strDecRed As String
Dim strDecGreen As String
Dim strDecBlue As String
' Remove # character
If Left(Hex, 1) = "#" Then
Hex = Right(Hex, (Len(Hex) - 1))
End If
' Fix length of hex color to 6 characters
If Len(Hex) > 6 Then
Hex = Left(Hex, 6)
End If
' Set RGB hex values
strHexRed = Left(Hex, 2)
strHexGreen = Mid(Hex, 3, 2)
strHexBlue = Right(Hex, 2)
' Set RGB dec values
strDecRed = CLng("&H" & strHexRed)
strDecGreen = CLng("&H" & strHexGreen)
strDecBlue = CLng("&H" & strHexBlue)
' Return colour to calling code
Return (Color.FromArgb(strDecRed, strDecGreen, strDecBlue))
End Function
Which I can now call like thus:
cell.backcolor = HexToDec("#d4c5db")
or
cell.backcolor = HexToDec("d4c5db")
Seems to work well - if anyone has better solutions I'm open to suggestions
:o)
Regards
Rob
why not use thi
Control.BackColor = Color.FromName("#d4c5db"
HT
Trevor Benedict R
"Trevor Benedict R" wrote ...
> Control.BackColor = Color.FromName("#d4c5db")
Hi Trevor...erm...you gotta be shittin' me? Does that actually work! I
assumed that the FromName would represent the names of the colours built
into VS - ie, White, Black, Red, Green and so on....
LOL - oh well, it was fun writing my useless function! :o)
Regards
Rob
0 comments:
Post a Comment