https://github.com/msdn-whiteknight/htmldocumentfactory
Helper library to assist in HTML creation with WinForms HtmlDocument class
https://github.com/msdn-whiteknight/htmldocumentfactory
csharp csharp-library dotnet html html-generation winforms
Last synced: about 1 month ago
JSON representation
Helper library to assist in HTML creation with WinForms HtmlDocument class
- Host: GitHub
- URL: https://github.com/msdn-whiteknight/htmldocumentfactory
- Owner: MSDN-WhiteKnight
- License: bsd-3-clause
- Created: 2018-05-19T16:26:32.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-19T17:50:42.000Z (almost 7 years ago)
- Last Synced: 2024-10-11T20:34:43.726Z (7 months ago)
- Topics: csharp, csharp-library, dotnet, html, html-generation, winforms
- Language: C#
- Homepage:
- Size: 37.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HtmlDocumentFactory
Windows Forms framework has a nice `HtmlDocument` class for HTML manupulation. However, it can only work with documents from `WebBrowser` control, and there's no public constructor to create new `HtmlDocument` instance from scratch. This library attempts to fix this problem. It consists of a single static class `HtmlLib.HtmlDocumentFactory` that provides helper methods for creating and destroying HTML documents and converting them to strings.
[Download binaries](https://yadi.sk/d/lPk5bGov3WCXsD)
**Usage**
Add reference to *HtmlDocumentFactory.dll* and import namespace with `using HtmlLib;` clause.
Create a new instance of HtmlDocument:
HtmlDocument htmldoc = HtmlDocumentFactory.CreateHtmlDocument();
Modify document's content like you wish:
HtmlElement el = htmldoc.CreateElement("div");
el.InnerText = "Hello, world!";
el.Style = "color: red";
htmldoc.Body.AppendChild(el);Copy resulting HTML to string object:
textBox1.Text = HtmlDocumentFactory.HtmlDocumentToString(htmldoc);
Free unmanaged resources when you no longer need the document:HtmlDocumentFactory.ReleaseHtmlDocument(htmldoc);
If you need to create HtmlDocument based on existing HTML content, pass a string into CreateHtmlDocument method:string html = "
Hello, world!
";
HtmlDocument htmldoc = HtmlDocumentFactory.CreateHtmlDocument(html);