抱歉,我刚才没有管理好帖子。现在为 hl0071 重新发表:
靠,我是一个新手,刚学VB没几天,现在遇到一个问题,想请教一下各位大腕们,是这样的,我想用PICTURE和TIMER来实现图象在窗体内像桌球一样弹来弹去,就像一些网站上的悬浮广告一样,我编了下面的代码但就是不行:
Private Sub Form_Load()
Timer1.Interval = 10
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim a As Integer, b As Integer, c As Integer
a = Picture1.Left + 50
b = Picture1.Top - 50
For a = 0 To Form1.Width - Picture1.Width " 不知道用循环结构行不行"
Select Case a
Case Is > Form1.Width - Picture1.Width
a = Picture1.Left - 50
Case Is < 0
a = Picture1.Left + 50
End Select
Next a
For b = 0 To Form1.Height - Picture1.Height
Select Case b
Case Is < 0
b = Picture1.Top + 50
Case Is > Form1.Height - Picture1.Height
b = Picture1.Top - 50
End Select
Next b
Picture1.Move a, b
End Sub
这样图像一下子跑到右下角就不动了,不知道哪里错了,请多多指教.另外我又编了另外一个代码还是不行:
Private Sub Form_Load()
Timer1.Interval = 10
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim a As Integer, b As Integer, c As Integer
a = Picture1.Left + 50
b = Picture1.Top - 50
if a> Form1.Width - Picture1.Width then
a = Picture1.Left - 50
end if
if a< 0 then
a = Picture1.Left + 50
end if
if b < 0 then
b = Picture1.Top + 50
end if
if b>Form1.Height - Picture1.Height then
b = Picture1.Top - 50
end if
Picture1.Move a, b
end sub