skip navigation
  • Product Bundles

    DevCraft

    All Telerik .NET tools and Kendo UI JavaScript components in one package. Now enhanced with:

    • AI Coding Assistants
    • Embedded Reporting
    • Document Processing Libraries
    • SSO Account Sign-in

    Web

    Kendo UI UI for Angular UI for Vue UI for jQuery KendoReact UI for Blazor UI for ASP.NET Core UI for ASP.NET MVC UI for ASP.NET AJAX

    Mobile

    UI for .NET MAUI

    Document Management

    Telerik Document Processing

    Desktop

    UI for .NET MAUI UI for WinUI UI for WinForms UI for WPF

    Reporting

    Telerik Reporting Telerik Report Server

    Testing & Mocking

    Test Studio Telerik JustMock

    CMS

    Sitefinity

    AI Productivity Tools

    AI Coding Assistants

    UI/UX Tools

    ThemeBuilder Design System Kit Templates and Building Blocks

    Debugging

    Fiddler Fiddler Everywhere Fiddler Classic Fiddler Everywhere Reporter FiddlerCore

    Free Tools

    KendoReact Free VB.NET to C# Converter Testing Framework
    View all products
  • Overview
  • Demos
    • What's New
    • Roadmap
    • Release History
  • Support and Learning

    • Support and Learning Hub
    • First Steps
    • Docs
    • Demos
    • Virtual Classroom
    • Forums
    • Videos
    • Blogs
    • Accessibility
    • Submit a Ticket

    Productivity and Design Tools

    • Visual Studio Extensions
    • Visual Studio Templates
    • Embedded Reporting
  • Pricing
  • Shopping cart
    • Account Overview
    • Your Licenses
    • Downloads
    • Support Center
    • Forum Profile
    • Payment Methods
    • Edit Profile
    • Log out
  • Login
  • Contact Us
  • Try now

Class HtmlContainer

Low level handling of Html Renderer logic, this class is used by TheArtOfDev.HtmlRenderer.Core.Parse.HtmlParser and HtmlRender.

Inheritance
System.Object
HtmlContainer
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: TheArtOfDev.HtmlRenderer.WinForms
Assembly: Telerik.WinControls.RadMap.dll

Syntax

public sealed class HtmlContainer : IDisposable

Constructors

HtmlContainer()

Init.

Declaration
public HtmlContainer()

Properties

ActualSize

The actual size of the rendered html (after layout)

Declaration
public SizeF ActualSize { get; }
Property Value
System.Drawing.SizeF

AvoidAsyncImagesLoading

Gets or sets a value indicating if image asynchronous loading should be avoided (default - false).
True - images are loaded synchronously during html parsing.
False - images are loaded asynchronously to html parsing when downloaded from URL or loaded from disk.

Declaration
public bool AvoidAsyncImagesLoading { get; set; }
Property Value
System.Boolean

Remarks

Asynchronously image loading allows to unblock html rendering while image is downloaded or loaded from disk using IO ports to achieve better performance.
Asynchronously image loading should be avoided when the full html content must be available during render, like render to image.

AvoidGeometryAntialias

Gets or sets a value indicating if anti-aliasing should be avoided for geometry like backgrounds and borders (default - false).

Declaration
public bool AvoidGeometryAntialias { get; set; }
Property Value
System.Boolean

AvoidImagesLateLoading

Gets or sets a value indicating if image loading only when visible should be avoided (default - false).
True - images are loaded as soon as the html is parsed.
False - images that are not visible because of scroll location are not loaded until they are scrolled to.

Declaration
public bool AvoidImagesLateLoading { get; set; }
Property Value
System.Boolean

Remarks

Images late loading improve performance if the page contains image outside the visible scroll area, especially if there is large amount of images, as all image loading is delayed (downloading and loading into memory).
Late image loading may effect the layout and actual size as image without set size will not have actual size until they are loaded resulting in layout change during user scroll.
Early image loading may also effect the layout if image without known size above the current scroll location are loaded as they will push the html elements down.

CssData

the parsed stylesheet data used for handling the html

Declaration
public CssData CssData { get; }
Property Value
CssData

IsContextMenuEnabled

Is the build-in context menu enabled and will be shown on mouse right click (default - true)

Declaration
public bool IsContextMenuEnabled { get; set; }
Property Value
System.Boolean

IsSelectionEnabled

Is content selection is enabled for the rendered html (default - true).
If set to 'false' the rendered html will be static only with ability to click on links.

Declaration
public bool IsSelectionEnabled { get; set; }
Property Value
System.Boolean

Location

The top-left most location of the rendered html.
This will offset the top-left corner of the rendered html.

Declaration
public PointF Location { get; set; }
Property Value
System.Drawing.PointF

MaxSize

The max width and height of the rendered html.
The max width will effect the html layout wrapping lines, resize images and tables where possible.
The max height does NOT effect layout, but will not render outside it (clip).
ActualSize can be exceed the max size by layout restrictions (unwrappable line, set image size, etc.).
Set zero for unlimited (width\height separately).

Declaration
public SizeF MaxSize { get; set; }
Property Value
System.Drawing.SizeF

ScrollOffset

The scroll offset of the html.
This will adjust the rendered html by the given offset so the content will be "scrolled".

Declaration
public Point ScrollOffset { get; set; }
Property Value
System.Drawing.Point

Examples

Element that is rendered at location (50,100) with offset of (0,200) will not be rendered as it will be at -100 therefore outside the client rectangle.

SelectedHtml

Copy the currently selected html segment with style.

Declaration
public string SelectedHtml { get; }
Property Value
System.String

SelectedText

Get the currently selected text segment in the html.

Declaration
public string SelectedText { get; }
Property Value
System.String

UseGdiPlusTextRendering

Use GDI+ text rendering to measure/draw text.

Declaration
public bool UseGdiPlusTextRendering { get; set; }
Property Value
System.Boolean

Remarks

GDI+ text rendering is less smooth than GDI text rendering but it natively supports alpha channel thus allows creating transparent images.

While using GDI+ text rendering you can control the text rendering using System.Drawing.Graphics.TextRenderingHint, note that using System.Drawing.Text.TextRenderingHint.ClearTypeGridFit doesn't work well with transparent background.

Methods

ClearSelection()

Clear the current selection.

Declaration
public void ClearSelection()

Dispose()

Declaration
public void Dispose()
Implements
System.IDisposable.Dispose()

GetAttributeAt(Point, String)

Get attribute value of element at the given x,y location by given key.
If more than one element exist with the attribute at the location the inner most is returned.

Declaration
public string GetAttributeAt(Point location, string attribute)
Parameters
System.Drawing.Point location

the location to find the attribute at

System.String attribute

the attribute key to get value by

Returns
System.String

found attribute value or null if not found

GetElementRectangle(String)

Get the rectangle of html element as calculated by html layout.
Element if found by id (id attribute on the html element).
Note: to get the screen rectangle you need to adjust by the hosting control.

Declaration
public RectangleF? GetElementRectangle(string elementId)
Parameters
System.String elementId

the id of the element to get its rectangle

Returns
System.Nullable<System.Drawing.RectangleF>

the rectangle of the element or null if not found

GetHtml(HtmlGenerationStyle)

Get html from the current DOM tree with style if requested.

Declaration
public string GetHtml(HtmlGenerationStyle styleGen = HtmlGenerationStyle.Inline)
Parameters
HtmlGenerationStyle styleGen

Optional: controls the way styles are generated when html is generated (default: Inline)

Returns
System.String

generated html

GetLinkAt(Point)

Get css link href at the given x,y location.

Declaration
public string GetLinkAt(Point location)
Parameters
System.Drawing.Point location

the location to find the link at

Returns
System.String

css link href if exists or null

GetLinks()

Get all the links in the HTML with the element rectangle and href data.

Declaration
public List<LinkElementData<RectangleF>> GetLinks()
Returns
System.Collections.Generic.List<LinkElementData<System.Drawing.RectangleF>>

collection of all the links in the HTML

HandleKeyDown(Control, KeyEventArgs)

Handle key down event for selection and copy.

Declaration
public void HandleKeyDown(Control parent, KeyEventArgs e)
Parameters
System.Windows.Forms.Control parent

the control hosting the html to invalidate

System.Windows.Forms.KeyEventArgs e

the pressed key

HandleMouseDoubleClick(Control, MouseEventArgs)

Handle mouse double click to select word under the mouse.

Declaration
public void HandleMouseDoubleClick(Control parent, MouseEventArgs e)
Parameters
System.Windows.Forms.Control parent

the control hosting the html to set cursor and invalidate

System.Windows.Forms.MouseEventArgs e

mouse event args

HandleMouseDown(Control, MouseEventArgs)

Handle mouse down to handle selection.

Declaration
public void HandleMouseDown(Control parent, MouseEventArgs e)
Parameters
System.Windows.Forms.Control parent

the control hosting the html to invalidate

System.Windows.Forms.MouseEventArgs e

the mouse event args

HandleMouseLeave(Control)

Handle mouse leave to handle hover cursor.

Declaration
public void HandleMouseLeave(Control parent)
Parameters
System.Windows.Forms.Control parent

the control hosting the html to set cursor and invalidate

HandleMouseMove(Control, MouseEventArgs)

Handle mouse move to handle hover cursor and text selection.

Declaration
public void HandleMouseMove(Control parent, MouseEventArgs e)
Parameters
System.Windows.Forms.Control parent

the control hosting the html to set cursor and invalidate

System.Windows.Forms.MouseEventArgs e

the mouse event args

HandleMouseUp(Control, MouseEventArgs)

Handle mouse up to handle selection and link click.

Declaration
public void HandleMouseUp(Control parent, MouseEventArgs e)
Parameters
System.Windows.Forms.Control parent

the control hosting the html to invalidate

System.Windows.Forms.MouseEventArgs e

the mouse event args

PerformLayout(Graphics)

Measures the bounds of box and children, recursively.

Declaration
public void PerformLayout(Graphics g)
Parameters
System.Drawing.Graphics g

Device context to draw

PerformPaint(Graphics)

Render the html using the given device.

Declaration
public void PerformPaint(Graphics g)
Parameters
System.Drawing.Graphics g

the device to use to render

SetHtml(String, CssData)

Init with optional document and stylesheet.

Declaration
public void SetHtml(string htmlSource, CssData baseCssData = null)
Parameters
System.String htmlSource

the html to init with, init empty if not given

CssData baseCssData

optional: the stylesheet to init with, init default if not given

Events

ImageLoad

Raised when an image is about to be loaded by file path or URI.
This event allows to provide the image manually, if not handled the image will be loaded from file or download from URI.

Declaration
public event EventHandler<HtmlImageLoadEventArgs> ImageLoad
Event Type
System.EventHandler<HtmlImageLoadEventArgs>

LinkClicked

Raised when the user clicks on a link in the html.
Allows canceling the execution of the link.

Declaration
public event EventHandler<HtmlLinkClickedEventArgs> LinkClicked
Event Type
System.EventHandler<HtmlLinkClickedEventArgs>

LoadComplete

Raised when the set html document has been fully loaded.
Allows manipulation of the html dom, scroll position, etc.

Declaration
public event EventHandler LoadComplete
Event Type
System.EventHandler

Refresh

Raised when html renderer requires refresh of the control hosting (invalidation and re-layout).

Declaration
public event EventHandler<HtmlRefreshEventArgs> Refresh
Event Type
System.EventHandler<HtmlRefreshEventArgs>

Remarks

There is no guarantee that the event will be raised on the main thread, it can be raised on thread-pool thread.

RenderError

Raised when an error occurred during html rendering.

Declaration
public event EventHandler<HtmlRenderErrorEventArgs> RenderError
Event Type
System.EventHandler<HtmlRenderErrorEventArgs>

Remarks

There is no guarantee that the event will be raised on the main thread, it can be raised on thread-pool thread.

ScrollChange

Raised when Html Renderer request scroll to specific location.
This can occur on document anchor click.

Declaration
public event EventHandler<HtmlScrollEventArgs> ScrollChange
Event Type
System.EventHandler<HtmlScrollEventArgs>

StylesheetLoad

Raised when a stylesheet is about to be loaded by file path or URI by link element.
This event allows to provide the stylesheet manually or provide new source (file or Uri) to load from.
If no alternative data is provided the original source will be used.

Declaration
public event EventHandler<HtmlStylesheetLoadEventArgs> StylesheetLoad
Event Type
System.EventHandler<HtmlStylesheetLoadEventArgs>

Extension Methods

SvgExtentions.Traverse<T>(T, Func<T, IEnumerable<T>>)
SvgExtentions.TraverseDepthFirst<T>(T, Func<T, IEnumerable<T>>)

See Also

TheArtOfDev.HtmlRenderer.WinForms.HtmlContainer.HtmlContainerInt
Getting Started
  • Install Now
  • Demos
  • Step-by-Step Tutorial
  • Sample Applications
  • SDK Samples
  • Visual Studio Extensions
Support Resources
  • Code Library
  • Knowledge Base
  • Videos
Community
  • Forums
  • Blogs
  • Feedback Portal
  • Document Processing Feedback Portal

Copyright © 2018 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.