楼上正解,没有给cpu空闲时间显示,一直在执行程序。
x.Show: DoEvents
'显示语句后加个释放时间片
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Dim x As Form1, i%, s%, n%, h%
For i = 1 To 20
Sleep 500
Randomize
n = Int(Rnd * 17000) + 10
h = Int(Rnd * 8800) + 10
Set x = New Form1
x.Show: DoEvents
x.Left = n
x.Top = h
x.Visible = True
x.Caption = "新创建的窗体" & x.Name
Next i
End Sub