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
: 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
: 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.
: 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...
Comments
:
:
: Mays
:
[code]
Private Sub cmdChangeBkG_Click()
Static BkGNormal As Boolean
Me.BackColor = IIF(BkGNormal, vbButtonFace, vbRed)
BkGNormal = Not BkGNormal
End Sub
[/code]
:
:
: 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
:-)
:
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...