cara membuat kotak berganti warna setiap beberapa detik dengan VB

langkah pertama masuk ke VB

buat kotak menggunakan label dengan mengganti autosize menjadi “false”

beri nomer (terserah)

masukkan timer1

masukkan coding berikut ini :

Public Class Timer_Lampu

Dim x As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Timer1.Enabled = True

Lbl1.BackColor = Color.Green

Lbl2.BackColor = Color.Gold

Lbl3.BackColor = Color.Green

Lbl4.BackColor = Color.Gold

Lbl5.BackColor = Color.Green

Lbl6.BackColor = Color.Gold

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

x = x + 1

If (x Mod 50 = 0) And (Lbl1.BackColor = Color.Green) Then

Lbl1.BackColor = Color.Gold

Lbl2.BackColor = Color.Green

ElseIf (x Mod 50 = 0) And (Lbl2.BackColor = Color.Green) Then

Lbl2.BackColor = Color.Gold

Lbl1.BackColor = Color.Green

End If

If (x Mod 100 = 0) And (Lbl3.BackColor = Color.Green) Then

Lbl3.BackColor = Color.Gold

Lbl4.BackColor = Color.Green

ElseIf (x Mod 100 = 0) And (Lbl4.BackColor = Color.Green) Then

Lbl4.BackColor = Color.Gold

Lbl3.BackColor = Color.Green

End If

If (x Mod 200 = 0) And (Lbl5.BackColor = Color.Green) Then

Lbl5.BackColor = Color.Gold

Lbl6.BackColor = Color.Green

ElseIf (x Mod 200 = 0) And (Lbl6.BackColor = Color.Green) Then

Lbl6.BackColor = Color.Gold

Lbl5.BackColor = Color.Green

End If

End Sub

End Class

berikut hasilnya :

Nb : warna bisa disesuaikan dengan mengganti BackColor pada Coding.

Sekian.. terima kasih dan semoga bermanfaat..

Tagged: , , , , , , ,

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: