怎么写代码来控制图片的移动?

来源:百度知道 编辑:UC知道 时间:2024/05/13 06:20:32
我说的是用vbkeyup之类的常数来控制,最好写出完整代码

picture1.left/top=picture1.left/top+/-xxx之类的

添加一image来试一下吧,用方向键来实现控件的控制。
代码如下:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 37 Then Image1.Move Image1.Left - 10, Image1.Top '左由于只向左移,TOP不变,所以也可以这样(Image1.Left=Image1.Left - 10)直接减小LEFT就行了.下面也一样.
If KeyCode = 38 Then Image1.Move Image1.Left, Image1.Top - 10 '上
If KeyCode = 39 Then Image1.Move Image1.Left + 10, Image1.Top '右
If KeyCode = 40 Then Image1.Move Image1.Left, Image1.Top + 10 '下
End Sub

Private Sub Form_Load()
Form1.KeyPreview = True '激活Form1上的控件的键盘事件之前,优先激活Form1键盘事件。
End Sub