由于其保护级别,它可能无法访问

Form1代码:

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    WebBrowser1.Navigate("http://www.----------.org/login.php?")
    WaitForPageLoad()
    WebBrowser1.Document.GetElementById("username").SetAttribute("value", TextBox1.Text)
    WebBrowser1.Document.GetElementById("password").SetAttribute("value", TextBox2.Text)
    WebBrowser1.Document.GetElementById("login").InvokeMember("Click")

End Sub

模块代码:

Private Property pageready As Boolean = False

区域“页面加载功能”

Private Sub WaitForPageLoad()
    AddHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
    While Not pageready
        Application.DoEvents()
    End While
    pageready = False
End Sub

Private Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
    If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
        pageready = True
        RemoveHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
    End If
End Sub

结束地区

所以我在互联网上搜索一个模块,可以让webbrowser1在继续下一个代码之前完全加载,我发现代码如何等待,直到WebBrowser完全加载到VB.NET中? ,但我在可访问性方面遇到了一些问题(在模块WebBrowser1。*和主窗体上),它没有声明,并且由于其保护级别而可能无法访问。 我是编程新手,希望有人能帮助我。

这里的图片链接http://s18.postimg.org/8qokcnzh5/Untitled.jpg


您的保护级别错误是由于您必须从您的模块WaitForPageLoad中访问Form1的按钮单击事件中的WaitForPageLoad()函数

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    WebBrowser1.Navigate("http://www.----------.org/login.php?")
    WaitForPageLoad.WaitForPageLoad() 'Example: ModuleName.FuncionOrMethodName()
    WebBrowser1.Document.GetElementById("username").SetAttribute("value", TextBox1.Text)
    WebBrowser1.Document.GetElementById("password").SetAttribute("value", TextBox2.Text)
    WebBrowser1.Document.GetElementById("login").InvokeMember("Click")
End Sub
  • 您需要公开您的WaitForPageLoad()以便您可以从Form1访问它。
  • 您将需要使用Form1访问WebBrowser1 (因为WebBrowser1位于Form1上
  • 新的WaitForPageLoad()

    Public Sub WaitForPageLoad()
        AddHandler Form1.WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
        While Not pageready
            Application.DoEvents()
        End While
        pageready = False
    End Sub
    
    Private Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
        If Form1.WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
            pageready = True
            RemoveHandler Form1.WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
        End If
    End Sub
    
    链接地址: http://www.djcxy.com/p/65211.html

    上一篇: vb.net it may be inaccessible due to its protection level

    下一篇: OLE: Inaccessible due to its protection level.