Results 1 to 8 of 8

Thread: Changing backcolor on a form

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2001
    Posts
    36

    Question Changing backcolor on a form

    I have a form with a trackbar control on it, the minimum value set to 0 and the maximum value set to 15. Each time the user changes the value of the trackbar by moving the slider, I would like to change the background color of the form that it is on to one of the 16 QBColors. In VB6, I was able to accomplish this with the statement

    Me.Backcolor = QBColor(Slider1.Value)

    However, in VB.NET, the only way that I have been able to accomplish the same effect is through a SELECT....CASE structure

    Select Case Trackbar1.Value

    Case 0:
    Me.Backcolor = System.Drawing.Color.Black
    Case 1:
    Me.Backcolor = System.Drawing.Color.Blue
    Case 2:
    Me.Backcolor = System.Drawing.Color.Green
    (etc.....)

    End Select

    Is there another more elegant way to do this without having to use the SELECT...CASE structure in VB.NET?

    --Steve K.

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Whats wrong with that way??
    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2001
    Posts
    36
    Probably nothing, it just seemed overly complicated given the simple, one-line solution that I had been using in VB6. I figured that perhaps I was overlooking a simpler way to do it (being as I'm new to VB.NET).

    Thanks for the response!

    --Steve K.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can get a color object from a color name string like this:
    VB Code:
    1. Me.BackColor = System.Drawing.Color.FromName("Red")

    There are similiar functions to get it from a RGB combo and things like that.

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    VB.NET is fully object oriented, so things that were simple in VB6, might not be so simple in .NET, since its applying OO rules.
    Dont gain the world and lose your soul

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2001
    Posts
    36
    I am beginning to get the idea that things are not quite as simple sometimes in VB.NET. My concern is whether or not I'm doing things "right" or not. Just as is with my original question - you can certainly accomplish changing the backcolor with the SELECT...CASE structure, but I wanted to be sure that I wasn't doing things the hard way.

    Thanks for the responses on this question!

    --Steve K.

  7. #7
    Lively Member
    Join Date
    Jul 2003
    Posts
    93
    Can anyone point out a place to get the numbers for a color. I need to find the exact match for a background I have selected & I'm not good enough with trying to go through and match it with custom colors. The color I am trying to match is LightSteelBlue.

    Thanks,
    Corinne

  8. #8
    Lively Member
    Join Date
    Jul 2003
    Posts
    93
    I came up with a site to help me with this. Maybe someone else is looking for the same thing:

    http://www.webcolors.freeserve.co.uk/mixer.htm

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