如何用vb控制图片实现模拟飞机移动,移动速度由滚动条决定,方向由键盘上的方向键控制。
Private Sub Form_Load()
Timer1.Interval = 10
Text1.Text = "→"
End Sub
Private Sub HScroll1_Change()
Text1.SetFocus
End Sub
Private Sub HScroll1_KeyPress(KeyAscii As Integer)
Text1.SetFocus
End Sub
Private Sub Text1_Keydown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 37
Text1.Text = "←"
Case 38
Text1.Text = "↑"
Case 39
Text1.Text = "→"
Case 40
Text1.Text = "↓"
End Select
End Sub
Private Sub Timer1_Timer()
Select Case Text1.Text
Case "←"
Me.Image1.Left = Me.Image1.Left - Me.HScroll1.Value
Case "↑"
Me.Image1.Top = Me.Image1.Top - Me.HScroll1.Value
Case "→"
Me.Image1.Left = Me.Image1.Left + Me.HScroll1.Value
Case "↓"
Me.Image1.Top = Me.Image1.Top + Me.HScroll1.Value
End Select
End Sub