vb.net webbrowser控件中的本地html url(visual basic)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22751994/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 17:15:33  来源:igfitidea点击:

Local html url in webbrowser control (visual basic)

vb.netbasic

提问by user3188039

I'm a beginner in VB, I'm trying to display html page in the webbrowser control. when I copy the full path of the html file, and put in the url properties of the webbrowser control, everything works. However, when I build the exe file and run it in different computer, the html page can not be displayed. I know this has to do with the html file path, I'm trying to find a way to display html page using webbrowser control in any computer.

我是 VB 的初学者,我正在尝试在 webbrowser 控件中显示 html 页面。当我复制 html 文件的完整路径,并放入 webbrowser 控件的 url 属性时,一切正常。但是,当我构建exe文件并在不同的计算机上运行它时,无法显示html页面。我知道这与 html 文件路径有关,我正在尝试找到一种在任何计算机上使用 webbrowser 控件显示 html 页面的方法。

any help will be great guys.

任何帮助都会是好人。

回答by Lukas2

Try:

尝试:

WebBrowser1.Navigate(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) & "\info.html")

remember to add

记得添加

Imports System.IO

回答by AJDev

This is a little late, but better late then never! Sorry I did not find this sooner! Anyway, instead of adding the file url in the URL property of WebBrowser1, here is what you need to do:

这有点晚了,但迟到总比没有好!抱歉我没有早点找到这个!无论如何,不​​是在 WebBrowser1 的 URL 属性中添加文件 url,而是您需要执行的操作:

  1. In Form1_Loadadd the following code:

    Dim appPath As String appPath = Application.StartupPath WebBrowser1.Navigate(appPath & "/html-file-name-here.html")

  2. Change the "html-file-name-here.html" to what your HTML file name is.
  3. Then when you compile your app, just put your html file in the folder where the app is launching from .
  1. Form1_Load添加以下代码:

    Dim appPath As String appPath = Application.StartupPath WebBrowser1.Navigate(appPath & "/html-file-name-here.html")

  2. 将“html-file-name-here.html”更改为您的 HTML 文件名。
  3. 然后当你编译你的应用程序时,只需将你的 html 文件放在应用程序启动的文件夹中。