Permalink
Browse files

Fix COMException on WebBrowser controls.

  • Loading branch information...
1 parent 13a8279 commit 14f31ba461c9096152b293f1da81f4a2aeafc1fb @rmcardle rmcardle committed Mar 16, 2013
@@ -55,9 +55,9 @@ Namespace Connection
Dim objWebBrowser As WebBrowser = TryCast(wBrowser, WebBrowser)
Dim objAxWebBrowser As SHDocVw.WebBrowser = DirectCast(objWebBrowser.ActiveXInstance, SHDocVw.WebBrowser)
- objWebBrowser.AllowWebBrowserDrop = False
objWebBrowser.ScrollBarsEnabled = True
+ AddHandler objWebBrowser.Navigated, AddressOf wBrowser_Navigated
AddHandler objWebBrowser.DocumentTitleChanged, AddressOf wBrowser_DocumentTitleChanged
AddHandler objAxWebBrowser.NewWindow3, AddressOf wBrowser_NewWindow3
End If
@@ -118,8 +118,14 @@ Namespace Connection
#End Region
#Region "Events"
- Private Sub gex_CreateWindow(ByVal sender As Object, ByVal e As Skybound.Gecko.GeckoCreateWindowEventArgs)
- e.WebBrowser = Me.wBrowser
+ Private Sub wBrowser_Navigated(sender As Object, e As System.Windows.Forms.WebBrowserNavigatedEventArgs)
+ Dim objWebBrowser As WebBrowser = TryCast(wBrowser, WebBrowser)
+ If objWebBrowser Is Nothing Then Return
+
+ ' This can only be set once the WebBrowser control is shown, it will throw a COM exception otherwise.
+ objWebBrowser.AllowWebBrowserDrop = False
+
+ RemoveHandler objWebBrowser.Navigated, AddressOf wBrowser_Navigated
End Sub
Private Sub wBrowser_NewWindow3(ByRef ppDisp As Object, ByRef Cancel As Boolean, ByVal dwFlags As Long, ByVal bstrUrlContext As String, ByVal bstrUrl As String)
@@ -177,6 +183,7 @@ Namespace Connection
End Enum
Private Enum NWMF
+ ' ReSharper disable InconsistentNaming
NWMF_UNLOADING = &H1
NWMF_USERINITED = &H2
NWMF_FIRST = &H4
@@ -191,6 +198,7 @@ Namespace Connection
NWMF_SUGGESTWINDOW = &H40000
NWMF_SUGGESTTAB = &H80000
NWMF_INACTIVETAB = &H100000
+ ' ReSharper restore InconsistentNaming
End Enum
#End Region
End Class
@@ -16,7 +16,6 @@ Namespace UI
'
'wBrowser
'
- Me.wBrowser.AllowWebBrowserDrop = False
Me.wBrowser.Dock = System.Windows.Forms.DockStyle.Fill
Me.wBrowser.Location = New System.Drawing.Point(0, 0)
Me.wBrowser.MinimumSize = New System.Drawing.Size(20, 20)
@@ -55,6 +54,11 @@ Namespace UI
Private Sub ApplyLanguage()
End Sub
+
+ Private Sub Announcement_Shown(sender As Object, e As EventArgs) Handles Me.Shown
+ ' This can only be set once the WebBrowser control is shown, it will throw a COM exception otherwise.
+ wBrowser.AllowWebBrowserDrop = False
+ End Sub
#End Region
Private aN As App.Announcement
@@ -52,7 +52,6 @@ Namespace UI
'
'wbHelp
'
- Me.wbHelp.AllowWebBrowserDrop = False
Me.wbHelp.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
@@ -224,6 +223,11 @@ Namespace UI
Me.tvIndex.SelectedNode = Me.tvIndex.Nodes(0).Nodes(0)
End Sub
+ Private Sub Help_Shown(sender As Object, e As EventArgs) Handles Me.Shown
+ ' This can only be set once the WebBrowser control is shown, it will throw a COM exception otherwise.
+ wbHelp.AllowWebBrowserDrop = False
+ End Sub
+
Private Sub tvIndex_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles tvIndex.NodeMouseClick
Me.tvIndex.SelectedNode = e.Node
End Sub

0 comments on commit 14f31ba

Please sign in to comment.