vb:窗体form1上有一个image1的控件,编程用键盘上的↑↓← →四个方向键控制image1控件的移动(快慢随意)
2个回答
展开全部
'窗体放一image1控件,设置Picture属性, 复制以下代码
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Me.Caption = KeyCode
Select Case KeyCode
Case 37 '左
Image1.Left = Image1.Left - 100
If Image1.Left < -Image1.Width Then Image1.Left = Me.Width '左边移除去了,右侧回来
Case 38 '上
Image1.Top = Image1.Top - 100
If Image1.Top < -Image1.Height Then Image1.Top = Me.Height '上面移出去了,下面回来
Case 39 '右
Image1.Left = Image1.Left + 100
If Image1.Left > Me.Width Then Image1.Left = -Image1.Width
Case 40 '下
Image1.Top = Image1.Top + 100
If Image1.Top > Me.Height Then Image1.Top = -Image1.Height
End Select
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Me.Caption = KeyCode
Select Case KeyCode
Case 37 '左
Image1.Left = Image1.Left - 100
If Image1.Left < -Image1.Width Then Image1.Left = Me.Width '左边移除去了,右侧回来
Case 38 '上
Image1.Top = Image1.Top - 100
If Image1.Top < -Image1.Height Then Image1.Top = Me.Height '上面移出去了,下面回来
Case 39 '右
Image1.Left = Image1.Left + 100
If Image1.Left > Me.Width Then Image1.Left = -Image1.Width
Case 40 '下
Image1.Top = Image1.Top + 100
If Image1.Top > Me.Height Then Image1.Top = -Image1.Height
End Select
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询