One Command Button to change multipul colors.

Hey I want to make one commando button to change the BackColor everytime I click it. I only know how to have it to change it to one. this is what I tried and it only turned the backround color Pink. This is the code I had. Im using Visual Basic 2008 Express

Public Class frmAlecdsk

Private Sub cmdColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdColor.Click
BackColor = Color.Black
BackColor = Color.Blue
BackColor = Color.Green
BackColor = Color.Yellow
BackColor = Color.Red
BackColor = Color.White
BackColor = Color.Gray
BackColor = Color.Pink
BackColor = Color.Purple
BackColor = Color.Orange
BackColor = Color.Brown
End Sub

Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
End
End Sub
End Class

Comments

  • Hi,
    I'm using visual Basic 6.0 but and I have come up with a rather inelegant solution for your problem.

    Private Sub Command1_Click()
    Count = Count + 1
    Select Case Count
    Case Is = 1
    Form1.BackColor = vbBlack
    Case Is = 2
    Form1.BackColor = vbBlue
    Case Is = 3
    Form1.BackColor = vbGreen
    Case Is = 4
    Form1.BackColor = vbYellow
    Case Is = 5
    Form1.BackColor = vbRed
    Case Is = 6
    Form1.BackColor = vbWhite
    Count = 0
    End Select
    End Sub

    Try that and see if it works.

    Good Luck
  • (I am a newbe in VB,I am using VB6 )

    no its not working its says..


    compile error

    function or interface marked as restricted,or the function uses an automation type not supported in Visual Basic,



    please help me what to do..
  • try this code..

    Option Explicit
    Dim count1 As Integer


    Private Sub Command1_Click()
    count1 = count1 + 1
    Select Case count1
    Case 1
    Form1.BackColor = vbBlue
    Case 2
    Form1.BackColor = vbRed
    Case 3
    Form1.BackColor = vbGreen
    Case 4
    Form1.BackColor = vbBlack
    count1 = 0
    End Select
    End Sub

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