关于图片移动的问题,请高人指点下

来源:百度知道 编辑:UC知道 时间:2024/06/24 19:24:42
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Static a%
a = a + 1
If Picture1.Top > Picture2.Top + Picture2.Height Then
Picture1.Move Picture1.Left, Picture1.Top - 5 - a, Picture1.Width, Picture1.Height
Else
Timer1.Enabled = False
End If
End Sub
目的:单击命令按钮时,图片1每隔0.1秒向上移动一次,当到达图片2的
下方时停止移动。
但是程序运行后点击后没反应,请问题错在哪里了?

我试了一下你的代码,有用!
你没有设置timer 控件的属性
要把timer1 的Interval属性设置为100 并且enabel 设置为false
(如果1000就是代表1秒)

'其他代码不变,只增加一行代码:

Private Sub Command1_Click()
Timer1.interval=100 '修改部分
Timer1.Enabled = True
End Sub

1、Timer 控件的生效,不只看 Enabled = True ,还需要 Interval = 100 属性;

2、为什么不直接用“Picture1.Top = Picture1.Top - 5 - a”呢?
使用 Move 方法,需要其他一些设置配合。