放上一ㄍ小圖型:如汽車,給予4個不同方向選項紐OptionButton(左方、正上方、左上方、右下方),案開始鈕後,圖形伊方向鈕不同,圖形就做不同方向的移動,案結束鈕程式中止。誰能幫幫偶押~~
2005-12-20 14:19:48 · 3 個解答 · 發問者 ︴戀〃封傷禁愛〃☆ 2 in 電腦與網際網路 ➔ 程式設計
拜託這方面高手幫偶一下吧~"~很急
2005-12-20 16:23:57 · update #1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a
PictureBox1.Left = 10
For a = 1 To 10
PictureBox1.Left += 10
System.Threading.Thread.Sleep(100)
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim b, x
PictureBox1.Left = 10
For b = 1 To 10
PictureBox1.Left -= 10
System.Threading.Thread.Sleep(100)
Next
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim c
PictureBox1.Top = 0
For c = 1 To 3
PictureBox1.Top -= 10
System.Threading.Thread.Sleep(100)
Next
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim d
PictureBox1.Top = 10
For d = 1 To 10
PictureBox1.Top += 10
System.Threading.Thread.Sleep(100)
Next
End Sub
End Class
------------------------------------------
上面是我自己寫的,你做參考吧,圖片自己隨便找一張貼在picturebox吧
Button4-->上移
Button5-->下移
Button1-->右移
Button3-->左移
Button2-->結束
2005-12-20 17:44:57 · answer #1 · answered by COLA 1 · 0⤊ 0⤋
ㄜ...好像怪怪的..= ="
2005-12-22 17:04:16 · answer #2 · answered by ︴戀〃封傷禁愛〃☆ 2 · 0⤊ 0⤋
表單佈置1個CommandButton,1個Timer,1個PictureBox,4個OptionButton陣列Option1(0)~Option1(3)
'--------------------------
Dim N As Long
Private Sub Command1_Click()
If Command1.Caption = "Start" Then
Command1.Caption = "Stop"
Else
Command1.Caption = "Start"
End If
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Form_Activate()
With Picture1
.Height = 600: .Width = 600
.Left = Me.ScaleWidth \ 2 - .Width \ 2
.Top = Me.ScaleHeight \ 2 - .Height \ 2
End With
With Command1
.Caption = "Start": .Height = 435: .Width = Me.ScaleWidth \ 5
.Left = 0: .Top = Me.ScaleHeight - .Height
End With
For I = 0 To 3
With Option1(I)
.Width = Command1.Width: .Height = Command1.Height
.Top = Command1.Top: .Left = Command1.Width * (I + 1)
End With
Next
Option1(0).Caption = "Left": Option1(1).Caption = "Right"
Option1(2).Caption = "UP": Option1(3).Caption = "Down"
Option1(1).Value = True
End Sub
Private Sub Form_Load()
Me.WindowState = 2
N = 200 '移動的距離
Timer1.Enabled = False
Timer1.Interval = 50 '移動的速度
End Sub
Private Sub Option1_Click(Index As Integer)
Command1.SetFocus
End Sub
Private Sub Timer1_Timer()
Dim Y As Long, X As Long
With Picture1
If Option1(0) Then
If .Left > N Then
.Left = .Left - N
ElseIf .Left > 0 And .Left <= N Then
.Left = 0
Else
Option1(1).Value = True
End If
ElseIf Option1(1) Then
X = Me.ScaleWidth - .Left - .Width
If X > N Then
.Left = .Left + N
ElseIf X <= N And X > 0 Then
.Left = Me.ScaleWidth - .Width
Else
Option1(0).Value = True
End If
ElseIf Option1(2) Then
If .Top > N Then
.Top = .Top - N
ElseIf .Top > 0 And .Top <= N Then
.Top = 0
Else
Option1(3).Value = True
End If
Else
Y = Me.ScaleHeight - .Top - .Height - Command1.Height
If Y > N Then
.Top = .Top + N
ElseIf Y <= N And Y > 0 Then
.Top = Me.ScaleHeight - .Height - Command1.Height
Else
Option1(2).Value = True
End If
End If
End With
Command1.SetFocus
End Sub
2005-12-20 18:39:45 · answer #3 · answered by W.J.S. 7 · 0⤊ 0⤋