VB中,如何让图像(image)在窗体中随机移动?

来源:百度知道 编辑:UC知道 时间:2024/09/22 19:30:07
如题。 在线等,重谢。。
宽度范围不限,高度范围在840-3200之间 .宽度限制在窗口课件范围~

可以利用定时器来实现
模型:Form1中有一个Image控件和Timer空格键
代码如下:
Private Sub Form_Load()
Timer1.Interval = 500
End Sub

Private Sub Timer1_Timer()

x = Int(Rnd * (Form1.Width - Image1.Width))
y = Int(Rnd * (Form1.Height - Image1.Height))
Image1.Left = x
Image1.Top = y
End Sub

randomize timer
image.height = int(rnd*(3200-840)+840)
image.width = int(rnd*form1.width) '宽度范围不限?还是限制在窗口可见范围内吧……

Private Sub Timer1_Timer()
Randomize
Image1.Left = Rnd * Form1.ScaleWidth
Image1.Top = Rnd * Form1.ScaleHeight
End Sub