下面这个希望可以帮到你~交通灯
实例说明在本实例中,我们将制作一个具有交通灯效果的应用程序。程序运行后,交通灯不断地变化,可以通过按钮运行或停止程序。程序运行结果如图88-1所示。技术要点l 不断变换图片l 不断更改时间间隔< type="text/javascript"> < type="text/javascript" src=" http://pagead2.googlesyndication.com/pagead/show_ads.js">
实现过程■ 新建项目打开Visual Studio.NET,选择"新建项目",在项目类型窗口中选择"Visual Basic项目",在模板窗口中选择"Windows应用程序",在名称域中输入"Traffic",然后选择保存路径。单击"确认"。■ 添加控件向当前窗体添加一个Timer控件,用于控制交通灯变换的时间;三个Picture控件,分别装入相应的图片;一个Button按钮,用于控制交通灯。属性保持默认值。■ 添加代码Dim vv As BooleanDim updirec As BooleanPrivate Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Clickvv = Timer1.Enabledvv = Not vvTimer1.Enabled = vvIf vv ThenCommand1.Text = "开 始"ElseCommand1.Text = "停 止"End IfEnd SubPrivate Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.TickStatic i As ShortSelect Case iCase 0Timer1.Interval = 3000picicon0.Visible = Truepicicon1.Visible = Falsepicicon2.Visible = Falsei = i + 1updirec = FalseCase 1Timer1.Interval = 1000picicon0.Visible = Falsepicicon1.Visible = Truepicicon2.Visible = False'Me.Icon = picicon(i).ImageIf updirec Theni = i - 1Elsei = i + 1End IfCase 2Timer1.Interval = 3000picicon0.Visible = Falsepicicon1.Visible = Falsepicicon2.Visible = Truei = i - 1updirec = TrueEnd SelectEnd Sub■ 运行程序单击菜单"调试|启动"或单击 图标运行程序。
写一个与上面例子不同的,参考学习吧加一个窗体,粘贴下面代码,运行即可 Public Class Form1
Dim cA() As Color = {Color.Lime, Color.Yellow, Color.Red}
Dim cB() As Color = {Color.DarkGreen, Color.DarkKhaki, Color.DarkRed}
Dim tmr() As Integer = {55, 5, 65}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = Not Timer1.Enabled
Button1.Text = IIf(Timer1.Enabled, "停止", "继续")
End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static A As Integer
Static T As Integer
If T = 0 Then A += 1
If A > 2 Then A = 0
T = tmr(A) * 2
lblTime.ForeColor = cA(A)
lblLamp.ForeColor = cA(A) Else
T -= 1 If T <= 10 Then
If T Mod 2 = 1 Then
lblTime.ForeColor = cA(A)
lblLamp.ForeColor = cA(A)
Else
lblTime.ForeColor = cB(A)
lblLamp.ForeColor = cB(A)
End If
End If
End If
lblTime.Text = (T \ 2).ToString
End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Button1 = New System.Windows.Forms.Button
Me.Panel1 = New System.Windows.Forms.Panel
Me.lblTime = New System.Windows.Forms.Label
Me.lblLamp = New System.Windows.Forms.Label
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.Panel1.SuspendLayout()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(298, 128)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(61, 28)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True
'
'Panel1
'
Me.Panel1.BackColor = System.Drawing.Color.Black
Me.Panel1.Controls.Add(Me.lblTime)
Me.Panel1.Controls.Add(Me.lblLamp)
Me.Panel1.Location = New System.Drawing.Point(28, 56)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(134, 42)
Me.Panel1.TabIndex = 1
'
'lblTime
'
Me.lblTime.AutoSize = True
Me.lblTime.BackColor = System.Drawing.Color.Transparent
Me.lblTime.Font = New System.Drawing.Font("宋体", 20.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.lblTime.ForeColor = System.Drawing.Color.Red
Me.lblTime.Location = New System.Drawing.Point(87, 9)
Me.lblTime.Name = "lblTime"
Me.lblTime.Size = New System.Drawing.Size(26, 27)
Me.lblTime.TabIndex = 0
Me.lblTime.Text = "0"
'
'lblLamp
'
Me.lblLamp.AutoSize = True
Me.lblLamp.BackColor = System.Drawing.Color.Transparent
Me.lblLamp.Font = New System.Drawing.Font("宋体", 20.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.lblLamp.ForeColor = System.Drawing.Color.DarkKhaki
Me.lblLamp.Location = New System.Drawing.Point(16, 9)
Me.lblLamp.Name = "lblLamp"
Me.lblLamp.Size = New System.Drawing.Size(39, 27)
Me.lblLamp.TabIndex = 0
Me.lblLamp.Text = "●"
'
'Timer1
'
Me.Timer1.Interval = 500
Me.Controls.Add(Me.Panel1)
Me.Controls.Add(Me.Button1)
Me.Panel1.ResumeLayout(False)
Me.Panel1.PerformLayout()
Me.ResumeLayout(False)
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents lblTime As System.Windows.Forms.Label
Friend WithEvents lblLamp As System.Windows.Forms.Label
Friend WithEvents Timer1 As System.Windows.Forms.Timer
End Class
什么时候要呢,我家有,公司没开发环境