开发者

convert c# to vb.net webbrowser

开发者 https://www.devze.com 2023-02-11 06:50 出处:网络
am trying to convert this c# to vb.net that has a webbrowser control, but am confused. the code is in a usercontrol.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消