Making a Traffic Light in VB.Net
Firstly insert some commands and text boxes:-command button 1 name it to "button1"
-command button 2 name it to "btn1"
-command button 3 name it to "btn2"
-command button 4 name it to "btn3"
-timer1
After insert these command press "F7" to go to code builder.
Secondly copy the code here and paste it in your code builder:
Sub red()
Me.btn1.BackColor = Color.Red
Me.btn2.BackColor = Color.DarkGray
Me.btn3.BackColor = Color.DarkGray
End Sub
Sub yellow()
Me.btn2.BackColor = Color.Yellow
Me.btn1.BackColor = Color.DarkGray
Me.btn3.BackColor = Color.DarkGray
End Sub
Sub blue()
Me.btn1.BackColor = Color.DarkGray
Me.btn2.BackColor = Color.DarkGray
Me.btn3.BackColor = Color.Blue
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Timer1.Start()
Me.Timer1.Interval = 100
Me.lbltext.Text = Microsoft.VisualBasic.Right(Me.lbltext.Text, Len(Me.lbltext.Text) - 1)
If Len(Me.lbltext.Text) >= 39 Then
Call blue()
Me.Button1.Text = Len(Me.lbltext.Text) - 9
ElseIf Len(Me.lbltext.Text) >= 10 Then
Call blue()
Me.Button1.Text = Len(Me.lbltext.Text) - 9
ElseIf Len(Me.lbltext.Text) >= 5 Then
Call yellow()
Me.Button1.Text = Len(Me.lbltext.Text) - 4
ElseIf Len(Me.lbltext.Text) >= 1 Then
Call red()
Me.Button1.Text = Len(Me.lbltext.Text)
ElseIf Me.lbltext.Text = "" Then
Me.lbltext.Text = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.btn1.BackColor = Color.DarkGray
Me.btn2.BackColor = Color.DarkGray
Me.btn3.BackColor = Color.DarkGray
Me.lbltext.Visible = False
End Sub
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
End Sub
Private Sub lbltext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbltext.Click
Me.Text = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
End Sub
Finally "Run" your application, for the faster the timer the smaller the interval.
if you want it slower use bigger interval value.
Share This:
-
Prevoius
-
NextYou are viewing Last Post
Can you make this program and give all source for me?
ReplyDeletethose are the codes, you can only just create a form then paste those code then it will works
DeleteI'm very try to do it, but it not work.!
DeleteHello! If you can please make it and send for me! Can tell me your phone number?
ReplyDeletelbltext.Text is not defined is it? what is it?
ReplyDelete