1

I have an HTML file, and I want to know how to know how to embed the file in a C# windows form application in Visual Studio 2019 (community edition). All I need is the html file to show up in the same window the Windows Forms app is located in.

Kool_Koder
  • 11
  • 3
  • 1
    Does this answer your question? [Display HTML on a winform](https://stackoverflow.com/questions/12724223/display-html-on-a-winform) – ADyson Mar 24 '21 at 20:56
  • Was my answer of use to you? Do you have any questions? My suggestion comes from working code (_very_ lightly edited) – Flydog57 Mar 25 '21 at 21:21

1 Answers1

0

This code is from more than a decade ago, but it works.

First:

  • Create your HTML file
  • Add it to your project
  • Set the properties for the file to
    • Build Action: EmbeddedResource
    • Copy to Output Directory: Do Not Copy

That will put your HTML file contents in your assembly as an embedded resource.

Then use code like this (in my case the html file is HelpText.htm):

Assembly thisAssembly=Assembly.GetExecutingAssembly();
string appName=thisAssembly.GetName().Name;
helpTextStream=thisAssembly.GetManifestResourceStream(appName+".HelpText.htm");
webBrowser1.DocumentStream=helpTextStream;

The webBrowser1 property is a WebBrowser control on a Windows Forms form.

You should also include code to Dispose the helpTextStream when you close the form.

Flydog57
  • 6,851
  • 2
  • 17
  • 18