Expert help needed ASAP!!!!!

Using Visual Basic 6, how could I make a button on my program that when clicked, changes the background color of the program then when you click it again it goes back to normal color? Please help me out here. Thanks


Mays

Comments

  • : Using Visual Basic 6, how could I make a button on my program that when clicked, changes the background color of the program then when you click it again it goes back to normal color? Please help me out here. Thanks
    :
    :
    : Mays
    :
    [code]
    Private Sub cmdChangeBkG_Click()

    Static BkGNormal As Boolean
    Me.BackColor = IIF(BkGNormal, vbButtonFace, vbRed)
    BkGNormal = Not BkGNormal

    End Sub
    [/code]
  • : Using Visual Basic 6, how could I make a button on my program that when clicked, changes the background color of the program then when you click it again it goes back to normal color? Please help me out here. Thanks
    :
    :
    : Mays
    :

    hi mays,
    if what you mean is form's background color, it's easy.
    try this:

    Private Sub Command1_Click()
    If Form1.BackColor = vbRed Then
    Form1.BackColor = vbButtonFace
    Else
    Form1.BackColor = vbRed
    End If
    End Sub

    you can change vbred with whatever color you desire.

    hope this helps

    :-)
  • Thank you so much! That really helped me out big time! I was stuck on it for a while.
  • Is there any possible way to make my button change....all....the backgrounds in my program to a certain color?
  • : Is there any possible way to make my button change....all....the backgrounds in my program to a certain color?
    :

    That's trickier, but yes. In my example, just add more controls to the list:
    [code]
    If BkGNormal Then
    Form1.BackColor = vbButtonFace
    Text1.BackColor = vbWhite 'Can't remember the correct system color constant
    Else
    Form1.BackColor = vbRed
    Text1.BackColor = vbBlue
    End If
    [/code]
    Some controls don't support getting their background color changed. Examples are commandbuttons and scrollbars. I don't completely recall how, but it involves using the control's hWnd to return and hDC (GetDC?) and then using another API to repaint the control...
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories