am trying to convert this c# to vb.net that has a webbrowser control, but am confused. the code is in a usercontrol.
c#
private void SetupEvents()
{
webBrowser1.Navigated += new WebBrowserNavigatedEventHandler(webBrowser1_Navigated);
webBrowser1.GotFocus += new EventHandler(webBrowser1_GotFocus开发者_JAVA百科);
}
[Browsable(true)]
public override Color BackColor
{
get
{
return base.BackColor;
}
set
{
base.BackColor = value;
if (ReadyState == ReadyState.Complete)
{
SetBackgroundColor(value);
}
}
}
public HtmlDocument Document
{
get { return webBrowser1.Document; }
}
the error 'Public Event Navigated(sender As Object, e As System.Windows.Forms.WebBrowserNavigatedEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
please help
try this code:
Private Sub SetupEvents()
AddHandler webBrowser1.Navigated, AddressOf Me.webBrowser1_Navigated
AddHandler webBrowser1.GotFocus, AddressOf Me.webBrowser1_GotFocus
End Sub
<Browsable(true)> _
Public Overrides Property BackColor As Color
Get
Return MyBase.BackColor
End Get
Set
MyBase.BackColor = value
If (ReadyState = ReadyState.Complete) Then
SetBackgroundColor(value)
End If
End Set
End Property
Public ReadOnly Property Document As HtmlDocument
Get
Return webBrowser1.Document
End Get
End Property
Private Sub SetupEvents()
AddHandler webBrowser1.Navigated, AddressOf Me.webBrowser1_Navigated
AddHandler webBrowser1.GotFocus, AddressOf Me.webBrowser1_GotFocus
End Sub
Assuming the webBrowser1_Navigated and webBroswer1_GotFocus are methods within this same class, then in the SetupEvents() method:
AddHandler WebBrowser1.Navigated, AddressOf webBrowser1_Navigated
AddHandler WebBrowser1.GotFocus, AddressOf webBrowser1_GotFocus
You have to use the AddHandler
keyword rather than += to set up your event handlers.
精彩评论