使用 vb.net 访问 Internet Explorer
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1868056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Accessing Internet Explorer using vb.net
提问by unsure
I'm trying to create a little executable that when launched opens an IE browser to various websites like news sites all in different tabs. for example, a tab for wsj, nytimes, etc. How do I access IE with vb.net? What reference do I need to add? I can't find any sample code that I can make work I think it is because I am missing a library in my assembly?
我正在尝试创建一个小的可执行文件,当启动它时,它会打开一个 IE 浏览器到各种网站,比如新闻网站,这些网站都在不同的选项卡中。例如,wsj、nytimes 等的选项卡。如何使用 vb.net 访问 IE?我需要添加什么参考?我找不到任何可以工作的示例代码,我认为是因为我的程序集中缺少一个库?
回答by kavian
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenURL("www.google.com")
End Sub
Private Sub OpenURL(ByVal URL As String)
System.Diagnostics.Process.Start(URL)
End Sub
'Or
'或者
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim TheBrowser As Object = CreateObject("InternetExplorer.Application")
TheBrowser.Visible = True
TheBrowser.Navigate("www.google.com")
End Sub
'Or add Reference SHDocVw.dll By Browsing System32
'或通过浏览System32添加Reference SHDocVw.dll
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim TheBrowser = New SHDocVw.InternetExplorerMedium
TheBrowser.Visible = True
TheBrowser.Navigate(URL:="http://www.google.com")
End Sub
回答by Stu
回答by AJ.
Is your application a console application? You can't create multiple tabs, but you can use a System.Diagnostics.Process
to launch individual instances of Internet Explorer. You should be able to simply specify the full address of the website as the Process to run, similar to how you can put "http://www.wsj.com" into a run prompt, which will launch your default browser with the Wall Street Journal's website.
您的应用程序是控制台应用程序吗?您不能创建多个选项卡,但可以使用System.Diagnostics.Process
来启动 Internet Explorer 的单个实例。您应该能够简单地将网站的完整地址指定为要运行的进程,类似于将“ http://www.wsj.com”放入运行提示中的方式,这将启动带有墙的默认浏览器街头日报的网站。
If you are using WinForms, you could always use a WebBrowser control, but that has limitations for tabs as well.
如果您使用的是 WinForms,您始终可以使用 WebBrowser 控件,但这对选项卡也有限制。