Setting table cell colors?

Discussion in 'ASP .Net' started by Rob Meade, Jun 6, 2004.

  1. Rob Meade

    Rob Meade Guest

    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
    Rob Meade, Jun 6, 2004
    #1
    1. Advertising

  2. Rob Meade

    Rob Meade Guest

    Bingo bango!

    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
    :eek:)

    Regards

    Rob
    Rob Meade, Jun 6, 2004
    #2
    1. Advertising

  3. RE: Bingo bango!

    why not use thi

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

    HT

    Trevor Benedict R
    =?Utf-8?B?VHJldm9yIEJlbmVkaWN0IFI=?=, Jun 7, 2004
    #3
  4. Rob Meade

    Rob Meade Guest

    Re: Bingo bango!

    "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! :eek:)

    Regards

    Rob
    Rob Meade, Jun 7, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phillip Roncoroni
    Replies:
    14
    Views:
    1,060
    Toby A Inkster
    Apr 5, 2004
  2. Kristian Virkus
    Replies:
    3
    Views:
    382
    Kristian Virkus
    Apr 10, 2004
  3. Jonathan N. Little

    Print tables with cell background colors

    Jonathan N. Little, Feb 8, 2007, in forum: HTML
    Replies:
    4
    Views:
    669
    OmegaJunior
    Feb 11, 2007
  4. AAaron123

    TreeNode colors come from anchor colors

    AAaron123, Aug 7, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    522
    darrel
    Aug 7, 2008
  5. ZelluX
    Replies:
    3
    Views:
    1,836
    Peter Otten
    Dec 1, 2008
Loading...

Share This Page