简体   繁体   English

vb.net如何从资源添加html文件并将其加载到webbrowser控件中

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

I have a webbrowser control on form2 , and the things I'd like to do are: 我在form2上有一个webbrowser控件,我想做的事情是:

  1. How can I add an HTML file into resource ? 如何将HTML文件添加到资源中?
  2. How can I load it from resource to webbrowser control when an if-condition is true , and make it visible in the webbrowser ? 如果if-condition为true ,如何将其从资源加载到webbrowser控件,并使其在webbrowser可见?

For example: 例如:

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

I've already tried the webbrowser.navigate but I want to load the HTML page. 我已经尝试过webbrowser.navigate但是我想加载HTML页面。

This work's for me and is tried and tested... I left the If condition out as it's not pertinent of what you are trying to accomplish. 这项工作适合我,并且已经过尝试和测试……我将If条件排除在外,因为它与您要完成的目标无关。 Also no need to call Navigate as when you set the Uri it should load the document. 另外,也无需调用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

Note 注意

If the Copy to Output Directory is not set to Copy Always for your html file (file's) you need to make that change. 如果您的html文件(文件)的“ Copy to Output Directory未设置为Copy Always ,则需要进行更改。 You can right click on the html file and select properties. 您可以右键单击html文件并选择属性。 Change that property as needed. 根据需要更改该属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM