Skip to main content
 首页 » 编程设计

c#之使用 C# 的 Windows 窗体应用程序中的 WebBrowser 控件

2024年01月29日29powertoolsteam

我正在尝试创建一个带有网络浏览器控件的表单。我正在尝试在 webbrowser 控件中打开一个本地 html 文件。我在 Help_Print 文件夹中有 html 文件,所以我使用下面的代码来指定网络浏览器的 Url。

wbPrint.Url = new Uri("file:///" + Application.StartupPath + "\\Help_Print\\help.html"); 

当窗体显示webbrowser控件时出现错误“该程序无法显示网页”。我已经检查了文件和文件夹位置。

但是当我尝试这样做时:

wbPrint.Url = new Uri("file:///" + Application.StartupPath + "/help.html"); 

将 html 文件复制到应用程序启动位置后,它可以正常工作。

任何人都可以解释为什么会这样,因为我想将所有 html 文件保存在一个单独的文件夹中。

请您参考如下方法:

不要在文件 URL 中使用黑色斜线。参见 the bizarre and unhappy story of file urls .