Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Setting table cell colors?

Reply
Thread Tools

Setting table cell colors?

 
 
Rob Meade
Guest
Posts: n/a
 
      06-06-2004
Hi all,

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

Rob


 
Reply With Quote
 
 
 
 
Rob Meade
Guest
Posts: n/a
 
      06-06-2004
Ok - 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
)

Regards

Rob


 
Reply With Quote
 
 
 
 
=?Utf-8?B?VHJldm9yIEJlbmVkaWN0IFI=?=
Guest
Posts: n/a
 
      06-07-2004
why not use thi

Control.BackColor = Color.FromName("#d4c5db"

HT

Trevor Benedict R
 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      06-07-2004
"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! )

Regards

Rob


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
form input text in table; how to fill table cell space sdf HTML 3 12-06-2007 03:29 PM
Table in a cell of another table Mark Goldin ASP .Net 2 08-19-2004 10:42 AM
A Challenge! (Setting table cell background permanently) Gary Hasler Javascript 4 07-20-2004 03:44 PM
How do I have a table cell fetch another page to display within the cell? Phillip Roncoroni HTML 14 04-05-2004 05:58 PM
Dynamic table, setting v-align of a new cell Rich Morey Javascript 2 08-26-2003 01:07 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57