Youtube转mp3转换器VB

时间:2015-07-29 23:00:56

标签: vb.net visual-studio-2012

我的VB代码出错:

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate("http://www.youtube-mp3.org/")
        Button1.Enabled = False
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Dim text As String = WebBrowser1.DocumentText

        If text.Contains("submit-form") Then
            Button1.Enabled = True
        Else
            Button1.Enabled = False
            MsgBox("Could not connect to the internet!", MsgBoxStyle.Information, "Error")
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Document.GetElementById("youtube-url").SetAttribute("value", TextBox1.Text)
        WebBrowser1.Document.GetElementById("submit").InvokeMember("click")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim dl_link As HtmlElement = WebBrowser1.Document.GetElementById("dl_link")
        Dim links As HtmlElementCollection = dl_link.GetElementsByTagName("a")
        Dim url As String = links(0).GetAttribute("href")
        System.Diagnostics.Process.Start(url)
    End Sub
End Class

我的错误是:

  

错误2 Handles子句需要在包含类型或其基类型之一中定义的WithEvents变量。

     

错误3' WebBrowser1'没有宣布。由于其保护级别,它可能无法访问。

     

错误3' WebBrowser1'没有宣布。由于其保护级别,它可能无法访问。

     

错误3' WebBrowser1'没有宣布。由于其保护级别,它可能无法访问。

     

错误3' WebBrowser1'没有宣布。由于其保护级别,它可能无法访问。

1 个答案:

答案 0 :(得分:0)

您需要将对象声明为表单。 只需通过从工具箱中拖动它来创建一个web浏览器。