vb.net 如何将 html 文件从资源添加并加载到网络浏览器控件中

vb.net how to add and load an html file from resource into webbrowser control

我在 form2 上有一个 webbrowser 控件,我想做的事情是:

  1. 如何将 HTML 文件添加到资源中?
  2. 当 if 条件为 true 时,如何将它从资源加载到 webbrowser 控件,并使其在 webbrowser 中可见?

例如:

 If dttest.Rows(0).Item(0).ToString = TextBox1.Text Then
  webbrowser.navigate(resources and the html name page)
 End If    

我已经试过 webbrowser.navigate 但我想加载 HTML 页面。

这项工作是为我准备的,并且已经过试验和测试...我将 If 条件排除在外,因为它与您要完成的工作无关。也不需要调用 Navigate 因为当你设置 Uri 它应该加载文档。

  Dim filename As String = "test.html"
  With Me.WebBrowser1 'Change name to reflect your name
      .ScriptErrorsSuppressed = True 'I was getting script errors from site
      .Url = New Uri(String.Format("file:///{0}{1}{2}/", System.IO.Directory.GetCurrentDirectory(), "/Resources/", filename))
  End With

备注

如果您的 html 文件的 Copy to Output Directory 未设置为 Copy Always,您需要进行更改。您可以右键单击 html 文件和 select 属性。根据需要更改 属性。