Class HtmlControl
Provides HTML rendering using the text property.
MewUI control that will render html content in it's client rectangle.
The control will handle mouse and keyboard events on it to support html text selection, copy-paste and mouse clicks.
The major differential to use HtmlPanel or HtmlLabel is size and scrollbars.
If the size of the control depends on the html content the HtmlLabel should be used.
If the size is set by some kind of layout then HtmlPanel is more suitable, also shows scrollbars if the html contents is larger than the control client rectangle.
LinkClicked event:
Raised when the user clicks on a link in the html.Allows canceling the execution of the link.
StylesheetLoad event:
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.
ImageLoad event:
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.
RenderError event:
Raised when an error occurred during html rendering.Inheritance
Inherited Members
Namespace: MewExtendedToolkit.Html
Assembly: MewExtendedToolkit.Html.dll
Syntax
public abstract class HtmlControl : Control, IDisposable, IVisualTreeHost
Constructors
| Edit this page View SourceHtmlControl()
Creates a new HtmlPanel and sets a basic css for it's styling.
Declaration
protected HtmlControl()
Fields
| Edit this page View SourceAvoidImagesLateLoadingProperty
Declaration
public static readonly MewProperty<bool> AvoidImagesLateLoadingProperty
Field Value
| Type | Description |
|---|---|
| MewProperty<bool> |
BaseStylesheetProperty
Declaration
public static readonly MewProperty<string> BaseStylesheetProperty
Field Value
| Type | Description |
|---|---|
| MewProperty<string> |
IsContextMenuEnabledProperty
Declaration
public static readonly MewProperty<bool> IsContextMenuEnabledProperty
Field Value
| Type | Description |
|---|---|
| MewProperty<bool> |
IsSelectionEnabledProperty
Declaration
public static readonly MewProperty<bool> IsSelectionEnabledProperty
Field Value
| Type | Description |
|---|---|
| MewProperty<bool> |
TextProperty
Declaration
public static readonly MewProperty<string> TextProperty
Field Value
| Type | Description |
|---|---|
| MewProperty<string> |
_baseCssData
the base stylesheet data used in the control
Declaration
protected CssData? _baseCssData
Field Value
| Type | Description |
|---|---|
| CssData |
_htmlContainer
Underline html container instance.
Declaration
protected readonly HtmlContainer _htmlContainer
Field Value
| Type | Description |
|---|---|
| HtmlContainer |
_lastScrollOffset
The last position of the scrollbars to know if it has changed to update mouse
Declaration
protected Point _lastScrollOffset
Field Value
| Type | Description |
|---|---|
| Point |
_mouseMovePoint
Declaration
protected Point _mouseMovePoint
Field Value
| Type | Description |
|---|---|
| Point |
Properties
| Edit this page View SourceAvoidImagesLateLoading
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
| Type | Description |
|---|---|
| bool |
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.
BaseStylesheet
Set base stylesheet to be used by html rendered in the panel.
Declaration
public string BaseStylesheet { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
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
| Type | Description |
|---|---|
| bool |
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
| Type | Description |
|---|---|
| bool |
SelectedHtml
Copy the currently selected html segment with style.
Declaration
[Browsable(false)]
public virtual string SelectedHtml { get; }
Property Value
| Type | Description |
|---|---|
| string |
SelectedText
Get the currently selected text segment in the html.
Declaration
[Browsable(false)]
public virtual string SelectedText { get; }
Property Value
| Type | Description |
|---|---|
| string |
Text
Gets or sets the text of this panel
Declaration
public string Text { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
| Edit this page View SourceClearSelection()
Clear the current selection.
Declaration
public void ClearSelection()
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 virtual Rect? GetElementRectangle(string elementId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | elementId | the id of the element to get its rectangle |
Returns
| Type | Description |
|---|---|
| Rect? | the rectangle of the element or null if not found |
GetHtml()
Get html from the current DOM tree with inline style.
Declaration
public virtual string? GetHtml()
Returns
| Type | Description |
|---|---|
| string | generated html |
HtmlHeight(Size)
Get the width the HTML has to render in (not including vertical scroll iff it is visible)
Declaration
protected virtual double HtmlHeight(Size size)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | size |
Returns
| Type | Description |
|---|---|
| double |
HtmlWidth(Size)
Get the width the HTML has to render in (not including vertical scroll iff it is visible)
Declaration
protected virtual double HtmlWidth(Size size)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | size |
Returns
| Type | Description |
|---|---|
| double |
InvokeMouseMove()
call mouse move to handle paint after scroll or html change affecting mouse cursor.
Declaration
protected virtual void InvokeMouseMove()
OnImageLoad(HtmlImageLoadEventArgs)
Propagate the image load event from root container.
Declaration
protected virtual void OnImageLoad(HtmlImageLoadEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| HtmlImageLoadEventArgs | e |
OnKeyDown(KeyEventArgs)
Handle key down event for selection, copy and scrollbars handling.
Declaration
protected override void OnKeyDown(KeyEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| KeyEventArgs | e |
Overrides
OnLinkClicked(HtmlLinkClickedEventArgs)
Propagate the LinkClicked event from root container.
Declaration
protected virtual void OnLinkClicked(HtmlLinkClickedEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| HtmlLinkClickedEventArgs | e |
OnLoadComplete(EventArgs)
Propagate the LoadComplete event from root container.
Declaration
protected virtual void OnLoadComplete(EventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| EventArgs | e |
OnMouseDoubleClick(MouseEventArgs)
Handle mouse double click to select word under the mouse.
Declaration
protected override void OnMouseDoubleClick(MouseEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| MouseEventArgs | e |
Overrides
OnMouseDown(MouseEventArgs)
Handle mouse down to handle selection.
Declaration
protected override void OnMouseDown(MouseEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| MouseEventArgs | e |
Overrides
OnMouseLeave()
Handle mouse leave to handle cursor change.
Declaration
protected override void OnMouseLeave()
Overrides
OnMouseMove(MouseEventArgs)
Handle mouse move to handle hover cursor and text selection.
Declaration
protected override void OnMouseMove(MouseEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| MouseEventArgs | e |
Overrides
OnMouseUp(MouseEventArgs)
Handle mouse up to handle selection and link click.
Declaration
protected override void OnMouseUp(MouseEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| MouseEventArgs | e |
Overrides
OnRefresh(HtmlRefreshEventArgs)
Handle html renderer invalidate and re-layout as requested.
Declaration
protected virtual void OnRefresh(HtmlRefreshEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| HtmlRefreshEventArgs | e |
OnRender(IGraphicsContext)
Perform paint of the html in the control.
Declaration
protected override void OnRender(IGraphicsContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| IGraphicsContext | context |
Overrides
OnRenderError(HtmlRenderErrorEventArgs)
Propagate the Render Error event from root container.
Declaration
protected virtual void OnRenderError(HtmlRenderErrorEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| HtmlRenderErrorEventArgs | e |
OnStylesheetLoad(HtmlStylesheetLoadEventArgs)
Propagate the stylesheet load event from root container.
Declaration
protected virtual void OnStylesheetLoad(HtmlStylesheetLoadEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| HtmlStylesheetLoadEventArgs | e |
TextPropertyChanged(string)
Declaration
protected virtual void TextPropertyChanged(string n)
Parameters
| Type | Name | Description |
|---|---|---|
| string | n |
Events
| Edit this page View SourceImageLoad
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 static event EventHandler<HtmlImageLoadEventArgs>? ImageLoad
Event Type
| Type | Description |
|---|---|
| EventHandler<HtmlImageLoadEventArgs> |
LinkClicked
Raised when the user clicks on a link in the html.
Allows canceling the execution of the link.
Declaration
public static event EventHandler<HtmlLinkClickedEventArgs>? LinkClicked
Event Type
| Type | Description |
|---|---|
| EventHandler<HtmlLinkClickedEventArgs> |
LoadComplete
Raised when the set html document has been fully loaded.
Allows manipulation of the html dom, scroll position, etc.
Declaration
public static event EventHandler<EventArgs>? LoadComplete
Event Type
| Type | Description |
|---|---|
| EventHandler<EventArgs> |
RenderError
Raised when an error occurred during html rendering.
Declaration
public static event EventHandler<HtmlRenderErrorEventArgs>? RenderError
Event Type
| Type | Description |
|---|---|
| EventHandler<HtmlRenderErrorEventArgs> |
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 static event EventHandler<HtmlStylesheetLoadEventArgs>? StylesheetLoad
Event Type
| Type | Description |
|---|---|
| EventHandler<HtmlStylesheetLoadEventArgs> |