Results 1 to 3 of 3

Thread: Setting backcolor dynamically

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2000
    Location
    Tennessee
    Posts
    279

    Question Setting backcolor dynamically

    I want to pull a string containing background color information from a database and dynamically set a form's background color.
    When I try to cast the string as "drawing.color" it errors out. Here's an example"


    dim backcolor as object

    backcolor = ds.Tables("BColor").Rows(0).Item("BackColor")

    Me.BackColor = CType(backcolor, System.Drawing.Color)


    Any help would be appreciated.
    A cynic knows the price of everything but the value of nothing.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can't just cast the string to a color object instead you have to use the Color object's FromName, FromRGB, or FromKnownName methods. Try this:
    VB Code:
    1. Me.BackColor = Color.FromName("Red")
    2. 'or in yours
    3. Me.BackColor = Color.FromName(ds.Tables("BColor").Rows(0).Item("BackColor"))

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2000
    Location
    Tennessee
    Posts
    279
    Excellent! Thanks alot!
    A cynic knows the price of everything but the value of nothing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width