2013-07-09 45 views
0

我需要關於VB等待網頁加載的幫助。 單擊一個按鈕=>導航一頁並等待加載,然後更改一個標籤文本,然後導航另一個頁面並等待加載,然後更改另一個標籤文本,然後導航並等待加載另一個頁面,然後更改標籤文本。請幫助我,我試着用這個代碼,但是失敗...VB等網頁加載

Private Sub Button1_Click ... 
WebBrowser1.Navigate("page1") 
Label1.Text = "Loaded" 'but this show before the page loaded 
WebBrowser1.Navigate("page2") 'this start loading before the page1 loaded 
Label2.Text = "Loaded" 'but this show before the page loaded 
WebBrowser1.Navigate("page3") 'this start loading before the page1 loaded 
Label3.Text = "Loaded" 
... 
End Sub 
+0

沒有爲web瀏覽器,你可以使用'DocumentCompleted'事件。 – ajakblackgoat

+0

是的,但如何使用它3-4-5頁。你能給我一個代碼嗎? :)) –

+0

在活動內部,檢查網頁瀏覽器的網址,並在此基礎上,將相應的標籤設置爲「已加載」。 – ajakblackgoat

回答

0

你只需要跟蹤哪一頁正在加載。你可以用Static變量來做到這一點。

當第一個完成時(documentcompleted事件觸發),然後加載下一個:

Private Sub Button1_Click 
    'Load the first page 
    LoadNextPage 
End Sub 

Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted 
    'When the current page has finished loading - load the next page 
    LoadNextPage 
End Sub 

Private Sub LoadNextPage 
    Static page As Integer = 0 'set to page number we are loading 
    'increment the page count 
    page += 1 
    'Load the appropriate page 
    Select Case page 
     Case 1 
      WebBrowser1.Navigate("page1") 
     Case 2 
      Label1.Text = "Loaded 1 now loading 2" 
      WebBrowser1.Navigate("page2") 
     Case 3 
      Label2.Text = "Loaded 2 now loading 3" 
      WebBrowser1.Navigate("page3") 
     Case Else 
      Label3.Text = "Loaded All Documents" 
    End Select 
End Sub 
+0

當我按下按鈕之前運行程序時,它就開始了。我怎樣才能解決這個問題? –

+0

你必須在Form_Load事件中有一些代碼呢? - 通過刪除該代碼來修復它。 –

+0

請給我你的電子郵件或Skype,我想問你一些問題 –