Join 300,412 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,594 people online right now. Registration is fast and FREE... Join Now!
Hi, I have this code to attach a new navigating event to a custom webbrowser control. Here it is:
CODE
Protected Friend Sub OnNewWindowExtended(ByVal Url As String, ByRef Cancel As Boolean, ByVal Flags As NWMF, ByVal UrlContext As String) Dim e As WebBrowserNewWindowExtendedEventArgs = New WebBrowserNewWindowExtendedEventArgs(Url, UrlContext, Flags) RaiseEvent NewWindowExtended(Me, e) Cancel = e.Cancel End Sub
However, on the (Me, E) code, I get an error, specifically: Value of type 'Net_Browser.browse.WebBrowserNewWindowExtendedEventArgs' cannot be converted to 'Net_Browser.browse.WebBrowserNewWindowExtendedEventHandler'.
I do not know what is happening here, as I have used this code on previous projects before. Can anyone help me?
Well, you're declaring a WebBrowserNewWindowExtendedEventArgs but you're trying to use it like a WebBrowserNewWindowExtendedEventHandler. Do you have the following event handlers and delegates defined in your code?
CODE
'This new event will fire when the page is navigating Public Delegate Sub WebBrowserNavigatingExtendedEventHandler(ByVal sender As Object, ByVal e As WebBrowserNavigatingExtendedEventArgs) Public Event NavigatingExtended As WebBrowserNavigatingExtendedEventHandler
'This event will fire when a new window is about to be opened Public Delegate Sub WebBrowserNewWindowExtendedEventHandler(ByVal sender As Object, ByVal e As WebBrowserNewWindowExtendedEventArgs) Public Event NewWindowExtended As WebBrowserNewWindowExtendedEventHandler
Public Class Browse Inherits Webbrowser Public Delegate Sub WebBrowserNavigatingExtendedEventHandler(ByVal sender As Object, ByVal e As browse.WebBrowserNavigatingExtendedEventHandler) Public Event NavigatingExtended As WebBrowserNavigatingExtendedEventHandler 'This event will fire when a new window is about to be opened Public Delegate Sub WebBrowserNewWindowExtendedEventHandler(ByVal sender As Object, ByVal e As browse.WebBrowserNewWindowExtendedEventHandler) Public Event NewWindowExtended As WebBrowserNewWindowExtendedEventHandler Private Sub nav() Handles Me.DocumentCompleted Dim pic As HtmlElement Dim pics As HtmlElementCollection = Me.Document.Images For Each pic In pics pic.AttachEventHandler("OnMousover", AddressOf OnEnter) Next Me.AllowNavigation = False Form1.AllowNav.Start() Dim link As HtmlElement Dim links As HtmlElementCollection = Me.Document.Links For Each link In links link.AttachEventHandler("onclick", AddressOf LinkClicked) Next Form1.ComboBox1.Text = CType(Form1.TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString Form1.Text = "Net Browser | " + CType(Form1.TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.Host() Form1.ComboBox2.Items.Add(Me.Url.ToString) Form1.Button7.Enabled = False Me.IsWebBrowserContextMenuEnabled = False Me.ContextMenuStrip = Form1.MyContextMenu Dim des As String = CType(Form1.TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle Dim position As Integer
If des.Length > 30 Then Do Until des.Length < 30 position = des.Length - 1 des = des.Remove(position, 1) Loop Form1.TabControl1.SelectedTab.Text = des + "..." Else Form1.TabControl1.SelectedTab.Text = des End If GetFavIcon() If CType(Form1.TabControl1.SelectedTab.Controls.Item(0), WebBrowser).ReadyState Then Form1.ToolStripProgressBar1.Visible = False End If Form1.webtimer2.Start() End Sub Dim href As String Private Sub OnEnter(ByVal sender As Object, ByVal e As EventArgs) MsgBox("Picure") End Sub Private Sub LinkClicked(ByVal sender As Object, ByVal e As EventArgs) Me.AllowNavigation = True href = Me.Document.ActiveElement.GetAttribute("href") If href.ToUpper.Contains(".wmv".ToUpper) Then Dim a As Windows.Forms.DialogResult = MsgBox("Do you want to play this file using media player, [Yes] or download it? [No]", MessageBoxButtons.YesNo, "Confirm") If a = Windows.Forms.DialogResult.Yes Then Me.AllowNavigation = False Form1.AllowNav.Start() Else Me.AllowNavigation = False Form1.DownloadTimer.Start() Me.Navigate(My.Settings.Homepage) End If ElseIf checklink() = True Then Me.AllowNavigation = False Form1.DownloadTimer.Start() Me.Navigate(My.Settings.Homepage) Else Me.Navigate(href) End If End Sub Public Function allownav() Me.AllowNavigation = True End Function Private Function checklink() As Boolean For Each item In My.Settings.LinkTypes If href.Contains(item) Then Form1.TextBox6.Text = item.ToString Return True Else Return False End If Next End Function
Protected Friend Sub OnNavigatingExtended(ByVal Url As String, ByVal Frame As String, ByVal Postdata As Byte(), ByVal Headers As String, ByRef Cancel As Boolean) Dim e As WebBrowserNavigatingExtendedEventArgs = New WebBrowserNavigatingExtendedEventArgs(Url, Frame, Postdata, Headers) RaiseEvent NavigatingExtended(Me, e) Cancel = e.Cancel End Sub
Protected Friend Sub OnNewWindowExtended(ByVal Url As String, ByRef Cancel As Boolean, ByVal Flags As NWMF, ByVal UrlContext As String) Dim e As WebBrowserNewWindowExtendedEventArgs = New WebBrowserNewWindowExtendedEventArgs(Url, UrlContext, Flags) RaiseEvent NewWindowExtended(Me, e) Cancel = e.Cancel End Sub
Public Delegate Sub WebBrowserNavigatingExtendedEventHandler(ByVal sender As Object, ByVal e As browse.WebBrowserNavigatingExtendedEventHandler) Public Event NavigatingExtended As WebBrowserNavigatingExtendedEventHandler 'This event will fire when a new window is about to be opened Public Delegate Sub WebBrowserNewWindowExtendedEventHandler(ByVal sender As Object, ByVal e As browse.WebBrowserNewWindowExtendedEventHandler)
In both e is of type WebBrowserNavigatingExtendedEventHandler and if you look at what I posted earlier e is of type WebBrowserNavigatingExtendedEventArgs, so when you're trying to call it with the way you're doing it it's yelling at you. Do you have a class WebBrowserNavigatingExtendedEventArgs? If not then take a look at this.