我正在尝试实现一个代码,该代码在用于在VB.NET中创建的选项卡式Web浏览器的新选项卡中打开链接。我有以下代码:
Private Sub OpenLinkInNewTabToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenLinkInNewTabToolStripMenuItem.Click
Dim Browser1 As New WebBrowser
Dim tabpage1 As TabPage = Browser1.Tag
TabControl1.TabPages.Add("New Page")
TabControl1.SelectTab(int1)
Browser1.Name = "Web Browser 1"
Browser1.Dock = DockStyle.Fill
TabControl1.SelectedTab.Controls.Add(Browser1)
AddHandler Browser1.ProgressChanged, AddressOf Loading1
AddHandler Browser1.DocumentCompleted, AddressOf Done1
int1 = int1 + 1
'Browser1.Navigate(Ele1.GetAttribute("href").ToString)
Browser1.Url = New Uri(DirectCast(Me.TabControl1.SelectedTab.Controls("Web Browser 1"), WebBrowser).Document.ActiveElement.GetAttribute("href"))
Try
If Browser1.DocumentTitle.Length > 25 Then
tabpage1.Text = Browser1.DocumentTitle.Substring(0, 25)
Else
tabpage1.Text = Browser1.DocumentTitle
End If
Browser1.ScriptErrorsSuppressed = True
Catch ex As Exception
End Try
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).IsWebBrowserContextMenuEnabled = False
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).ContextMenuStrip = ContextMenuStrip1
End Sub
但是,只要我点击任意链接并选择NullReferenceException
Browser1.Url = ...
行的Open in new tab
请帮帮我
编辑:我想要一个可以告诉我右键单击元素的解决方案。我以后可以存储元素的href
,将其转换为字符串,然后使用它进行导航。我几乎到处搜索,但找不到解决方案。