Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-access-the-managed-html-document-object-model.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

3.3 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Access the Managed HTML Document Object Model 03/30/2017
csharp
vb
HTML DOM [Windows Forms], accessing
managed HTML DOM [Windows Forms], accessing
40fa5cd5-1ed8-42f6-a93f-9ac01608bbeb

How to: Access the Managed HTML Document Object Model

You can access the managed HTML Document Object Model (DOM) from two types of applications:

To access DOM from a Windows Forms application

  1. Host a xref:System.Windows.Forms.WebBrowser control within your Windows Forms application and monitor for the xref:System.Windows.Forms.WebBrowser.DocumentCompleted event. For details on hosting controls and monitoring for events, see Events.

  2. Retrieve the xref:System.Windows.Forms.HtmlDocument for the current page by accessing the xref:System.Windows.Forms.WebBrowser.Document%2A property of the xref:System.Windows.Forms.WebBrowser control.

To access DOM from a UserControl hosted in Internet Explorer

  1. Create your own custom derived class of the xref:System.Windows.Forms.UserControl class. For more information, see How to: Author Composite Controls.

  2. Place the following code inside of your Load event handler for your xref:System.Windows.Forms.UserControl:

[!code-csharpAccessHTMLDOMControl#1] [!code-vbAccessHTMLDOMControl#1]

Robust Programming

  1. When using the DOM through the xref:System.Windows.Forms.WebBrowser control, you should always wait until the xref:System.Windows.Forms.WebBrowser.DocumentCompleted event occurs before attempting to access the xref:System.Windows.Forms.WebBrowser.Document%2A property of the xref:System.Windows.Forms.WebBrowser control. The xref:System.Windows.Forms.WebBrowser.DocumentCompleted event is raised after the entire document has loaded; if you use the DOM before then, you risk causing a run-time exception in your application.

.NET Framework Security

  1. Your application or xref:System.Windows.Forms.UserControl will require full trust in order to access the managed HTML DOM. If you are deploying a Windows Forms application using ClickOnce, you can request full trust using either Permission Elevation or Trusted Application Deployment; see Securing ClickOnce Applications for details.

See also