Public Class Form1 Dim m = 0 Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp Timer1.Stop() Timer2.Stop() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Start() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If (m = 1) Then v.Location = New Point(v.Location.X - 10, v.Location.Y) End If If (m = 2) Then v.Location = New Point(v.Location.X + 10, v.Location.Y) End If If (m = 0) Then End If End Sub Dim bullet As New PictureBox Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown Timer1.Start() If e.KeyCode = Keys.Space Then Timer2.Start() End If If e.KeyCode = Keys.Left Then m = 1 End If If e.KeyCode = Keys.Right Then m = 2 End If If (v.Location.X <= 0) Then v.Location = New Point(v.Location.X = 874, v.Location.Y) End If If (v.Location.X >= 875) Then v.Location = New Point(v.Location.X = 1, v.Location.Y) End If End Sub Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick bullet.BackColor = Color.Red bullet.Width = 20 bullet.Height = 40 bullet.Visible = True bullet.Location = New Point(v.Location.X, v.Location.Y + 1) End Sub End Class
PictureBox
System.Windows.Forms.Timer
Invoke/BeginInvoke
Form1
Form1_Load
Form1_KeyUp
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)