none
AxWebBrowser進行FileDownload RRS feed

  • 問題

  • 我在Frm_IEMain中設定,只要是有開啟新視窗時(window.open)
    就開啟Frm_IESub

    過程中都很順利 , 只是遇到 "檔案下載" 時
    我遇到困難了....

    以這個網站為例
    http://www.cht.com.tw/ServiceCat.php?Page=ApplyDownloadList&CatID=677
    我點選 "中華電信商務卡" , 它會開啟新視窗並執行下載檔案
    此時...有三個選項 "開啟檔案" "儲存" "取消"

    我在AxWebBrowser1_FileDownload事件中,"儲存" "取消"是可以完成工作

    唯獨選擇 "開啟檔案" 後 , 因為不知道AxWebBrowser目前的狀態
    以至於在Frm_IESub無法判斷是否要進行 Me.Close + Me.Dispose

    請各位前輩指點迷津

    Frm_IEMain
    Public Class Frm_IEMain
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            AxWebBrowser1.Navigate2("http://www.cht.com.tw/ServiceCat.php?Page=ApplyDownloadList&CatID=677")
        End Sub
    
        Private Sub AxWebBrowser1_NewWindow2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles AxWebBrowser1.NewWindow2
            Dim oFrmIESub As New Frm_IESub
            oFrmIESub.MdiParent = Me.MdiParent
            oFrmIESub.Show()
            e.ppDisp = oFrmIESub.AxWebBrowser1.Application
            oFrmIESub.AxWebBrowser1.RegisterAsBrowser = True
           
        End Sub
    End Class
    
    

    Frm_IESub
    Public Class Frm_IESub
    
        Private Sub AxWebBrowser1_FileDownload(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_FileDownloadEvent) Handles AxWebBrowser1.FileDownload
            '選擇[開啟檔案]時 , 不知如何判斷
    
            If AxWebBrowser1.Busy = False Then
                Me.Close()
                Me.Dispose()
            End If
    
            Try
                Select Case AxWebBrowser1.ReadyState
                    Case SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE, SHDocVw.tagREADYSTATE.READYSTATE_INTERACTIVE, SHDocVw.tagREADYSTATE.READYSTATE_LOADED, SHDocVw.tagREADYSTATE.READYSTATE_LOADING, SHDocVw.tagREADYSTATE.READYSTATE_UNINITIALIZED
    
    
                    Case Else
                        Me.Close()
                        Me.Dispose()
                End Select
            Catch ex As Exception
                Me.Close()
                Me.Dispose()
            End Try
    
        End Sub
    End Class
    
    
    2009年11月25日 上午 06:15

解答

所有回覆