Yes, it is possible, but look at what you're trying to do.
You pick the document Element, which is already the most "outer" in the document. Your can only take or write a whole different document.
[EDIT]
In this case you can only to create a document from scratch and start over. The class
System.Windows.Forms.HtmlDocument
does not have constructors or other means of explicit instantiating. You can obtain empty document via its instance of
System.Windows.Forms.WebBrowser
. Navigate to
(Uri)null
and you will get clean document when the event
System.Windows.Forms.WebBrowser.Navigated
is handled (important!). The property
System.Windows.Forms.WebBrowser.Document
will return empty document which you can populate.
Example:
bool startFromScratch = false;
startFromScratchButton.Click += (sender, eventArgs) => {
startFromScratch = true;
webBrowser.Navigate((Uri)null);
}
webBrowser.Navigated += (sender, eventArgs) => {
if (startFromScratch) {
var document = webBrowser.Document;
var body = document.Body;
document.Body.InnerHtml = "<p>some paragraph content</p>";
}
};
I tested it.
—SA