0

嗨,我有以下表格,但无法弄清楚为什么在单击不同按钮时它会直接终止?

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub


Private Sub button1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter

    Dim TEST1 As Integer = System.IO.Directory.GetFiles("C:\test\test").Length
    If TEST1 = 0 Then

        Me.WebBrowser1.Navigate("http://www.hotmail.com")

    End If

End Sub

Private Sub button1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
    Me.WebBrowser1.Navigate("http://WWW.facebook.com")
End Sub

Private Sub button2_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.MouseLeave
    Me.WebBrowser1.Navigate("http://WWW.facebook.com")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.WebBrowser1.Navigate("file://C:\test\test")
    Button1.Enabled = False
    Button2.Enabled = True

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    Me.WebBrowser1.Navigate("file://C:\test")
    Button2.Enabled = False
    Button1.Enabled = True
End Sub


Private Sub button2_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.MouseEnter

    Dim TEST2 As Integer = System.IO.Directory.GetFiles("C:\test\test").Length
    If TEST2 = 0 Then

        Me.WebBrowser1.Navigate("http://www.hotmail.com")

    End If

End Sub

facebook 和 hotmail 这两个术语是随机的,以保持公司网站的私密性 :)

4

1 回答 1

0

我怀疑该Mouse_Enter事件和Mouse_Leave事件没有给网络浏览器时间来完全加载文档,并且它可能在内部崩溃。

在再次导航之前尝试检查网络浏览器是否已完成工作并告诉我们:

利用

 If WebBrowser1.ReadyState = WebBrowserReadyState.Complete
      Me.WebBrowser1.Navigate("http://www.google.com")
 End if
于 2013-10-03T09:19:17.500 回答