Form1 code:Public num As Integer
Private Sub Command1_Click()    Timer1.Enabled = True
    Timer1.Interval = 1000
End SubPrivate Sub Timer1_Timer()
     num = num + 1
    WebBrowser1(num - 1).Navigate2 ("http://www.baidu.com")
    
    If num = 2 Then
        Timer1.Enabled = False
        num = 0
    End IfEnd SubPrivate Sub WebBrowser1_DocumentComplete(index As Integer, ByVal pDisp As Object, URL As Variant)
     On Error Resume Next
     If (pDisp Is WebBrowser1(index).Object) Then
        'MsgBox ("haha")
        Form2.Text1.Text = index
        Form2.Show 1
     End If
End Sub
Form2 codePrivate Sub Command1_Click()
    Unload Form2
End Sub大家复制代码运行一下就明白了 如果把'MsgBox ("haha")注释去掉 弹出msgbox时程序就会挂起 webbrowser1(1)也不会执行navigate2方法 模式窗口也会一个一个弹出来 但是没有msgbox的话 当第一个模式窗口出现一秒之后第二个模式窗口就会自动覆盖掉第一个窗口 我希望实现的效果是点击第一个窗口的按钮后再显示第二个窗口 请高手帮帮忙!

解决方案 »

  1.   

    模式窗口按理和msgbox都是可以让程序挂起的 可是为什么这里不行呢 纠结啊
      

  2.   

    看不大懂〜是要这样吗?点了Form2〜才开第二个之后的WebBrowser吗?Form1:Option ExplicitPublic num As IntegerPrivate Sub cmdCommand1_Click()
        Timer1.Enabled = True
        Timer1.Interval = 1000
    End SubPrivate Sub Form_Initialize()
        Status = False
    End SubPrivate Sub Timer1_Timer()    If num = 0 Then
            num = num + 1
            WebBrowser1(num - 1).Navigate2 ("http://www.baidu.com")
            Status = False
        ElseIf Status = True Then
            num = num + 1
            WebBrowser1(num - 1).Navigate2 ("http://www.baidu.com")
            Status = False
        End If
        
        If num = 3 Then
            Timer1.Enabled = False
            num = 0
        End If
        
        
    End SubPrivate Sub WebBrowser1_DocumentComplete(index As Integer, ByVal pDisp As Object, URL As Variant)On Error Resume Next     If (pDisp Is WebBrowser1(index).Object) Then
    '        MsgBox "haha"
            Form2.txtText1.Text = index
            Form2.Show 1
         End If
         
    End Sub
    Form2:Option ExplicitPrivate Sub cmdCommand1_Click()
        Unload Form2
        Status = True
    End Sub
    Module:Option ExplicitPublic Status As Boolean
      

  3.   

    vb里的form并非模式窗口。建议把Num的改变用按钮来控制。