展开全部
向右移动
Private Sub Command1_Click()
Picture1.Left = Picture1.Left + 200
If Picture1.Left > Form1.Width Then
Picture1.Left = -Picture1.Width
End If
End Sub
向左移动
Private Sub Command2_Click()
Picture1.Left = Picture1.Left - 200
If Picture1.Left < 0 Then
Picture1.Left = Form1.Width
End If
End Sub
向上移动
Private Sub Command3_Click()
Picture1.Top = Picture1.Top - 200
If Picture1.Top < -Picture1.Height Then
Picture1.Top = Form1.Height
End If
End Sub
向下移动
Private Sub Command4_Click()
Picture1.Top = Picture3.Top + 200
If Picture1.Top > Form1.Height Then
Picture1.Top = -Picture1.Height
End If
End Sub
Private Sub Command1_Click()
Picture1.Left = Picture1.Left + 200
If Picture1.Left > Form1.Width Then
Picture1.Left = -Picture1.Width
End If
End Sub
向左移动
Private Sub Command2_Click()
Picture1.Left = Picture1.Left - 200
If Picture1.Left < 0 Then
Picture1.Left = Form1.Width
End If
End Sub
向上移动
Private Sub Command3_Click()
Picture1.Top = Picture1.Top - 200
If Picture1.Top < -Picture1.Height Then
Picture1.Top = Form1.Height
End If
End Sub
向下移动
Private Sub Command4_Click()
Picture1.Top = Picture3.Top + 200
If Picture1.Top > Form1.Height Then
Picture1.Top = -Picture1.Height
End If
End Sub
展开全部
我使用是Image图片控件..
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 37
Call moveleft
Case 38
Call moveup
Case 39
Call moveright
Case 40
Call movedown
End Select
End Sub
Private Sub Form_Load()
Image1.Move 0, 0, 500, 500
End Sub
Sub moveleft()
If Image1.Left >= Image1.Width Then Image1.Left = Image1.Left - 500
End Sub
Sub moveup()
If Image1.Top >= Image1.Height Then Image1.Top = Image1.Top - 500
End Sub
Sub movedown()
If Image1.Top <= Me.ScaleHeight - Image1.Height * 2 Then Image1.Top = Image1.Top + 500
End Sub
Sub moveright()
If Image1.Left <= Me.ScaleWidth - Image1.Width * 2 Then Image1.Left = Image1.Left + 500
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 37
Call moveleft
Case 38
Call moveup
Case 39
Call moveright
Case 40
Call movedown
End Select
End Sub
Private Sub Form_Load()
Image1.Move 0, 0, 500, 500
End Sub
Sub moveleft()
If Image1.Left >= Image1.Width Then Image1.Left = Image1.Left - 500
End Sub
Sub moveup()
If Image1.Top >= Image1.Height Then Image1.Top = Image1.Top - 500
End Sub
Sub movedown()
If Image1.Top <= Me.ScaleHeight - Image1.Height * 2 Then Image1.Top = Image1.Top + 500
End Sub
Sub moveright()
If Image1.Left <= Me.ScaleWidth - Image1.Width * 2 Then Image1.Left = Image1.Left + 500
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在窗体的keyascii事件中判断键值
当是方向键时移动图片框
当是方向键时移动图片框
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询