C# Class LayoutFarm.Demo.HtmlPanel

Provides HTML rendering using the text property.
WinForms control that will render html content in it's client rectangle.
If AutoScroll is true and the layout of the html resulted in its content beyond the client bounds of the panel it will show scrollbars (horizontal/vertical) allowing to scroll the content.
If AutoScroll is false html content outside the client bounds will be clipped.
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.

AutoScroll:

Allows showing scrollbars if html content is placed outside the visible boundaries of the panel.

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: System.Windows.Forms.ScrollableControl
Mostra file Open project: prepare/HTML-Renderer Class Usage Examples

Private Properties

Property Type Description
BuildCssBoxTree void
CreateMouseEventArg LayoutFarm.UI.UIMouseEventArgs
GetDC IntPtr
GetSharedPainter PaintVisitor
GetUIMouseButton LayoutFarm.UI.UIMouseButtons
OnRefresh void
OnScrollChange void
PaintMe void
PaintMe void
PerformHtmlLayout void
ReleaseDC IntPtr
ReleaseSharedPainter void
SetHtml void
UpdateScroll void
myHtmlContainer_NeedUpdateDom void

Public Methods

Method Description
ForceRefreshHtmlDomChange ( LayoutFarm doc ) : void
GetHtml ( ) : string

Get html from the current DOM tree with inline style.

GetHtmlContainer ( ) : HtmlContainer
HtmlPanel ( PixelFarm p, int w, int h ) : System

Creates a new HtmlPanel and sets a basic css for it's styling.

LoadHtmlDom ( LayoutFarm doc, string defaultCss ) : void
SetHtmlHost ( HtmlHost htmlhost ) : void

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Release the html container resources.

IsInputKey ( Keys keyData ) : bool

Used to add arrow keys to the handled keys in OnKeyDown.

OnClick ( EventArgs e ) : void

Set focus on the control for keyboard scrrollbars handling.

OnKeyDown ( KeyEventArgs e ) : void

Handle key down event for selection, copy and scrollbars handling.

OnLayout ( LayoutEventArgs levent ) : void

Perform the layout of the html in the control.

OnMouseDown ( MouseEventArgs e ) : void

Handle mouse down to handle selection.

OnMouseLeave ( EventArgs e ) : void

Handle mouse leave to handle cursor change.

OnMouseMove ( MouseEventArgs e ) : void

Handle mouse move to handle hover cursor and text selection.

OnMouseUp ( MouseEventArgs e ) : void

Handle mouse up to handle selection and link click.

OnPaint ( PaintEventArgs e ) : void

Perform paint of the html in the control.

Private Methods

Method Description
BuildCssBoxTree ( MyHtmlContainer htmlCont, CssActiveSheet cssData ) : void
CreateMouseEventArg ( MouseEventArgs e ) : LayoutFarm.UI.UIMouseEventArgs
GetDC ( IntPtr hWnd ) : IntPtr
GetSharedPainter ( LayoutFarm htmlCont, PixelFarm canvas ) : PaintVisitor
GetUIMouseButton ( MouseButtons mouseButton ) : LayoutFarm.UI.UIMouseButtons
OnRefresh ( object sender, EventArgs e ) : void

Handle html renderer invalidate and re-layout as requested.

OnScrollChange ( object sender, HtmlScrollEventArgs e ) : void

On html renderer scroll request adjust the scrolling of the panel to the requested location.

PaintMe ( ) : void
PaintMe ( PaintEventArgs e ) : void
PerformHtmlLayout ( ) : void

Perform html container layout by the current panel client size.

ReleaseDC ( IntPtr hWnd, IntPtr hdc ) : IntPtr
ReleaseSharedPainter ( PaintVisitor p ) : void
SetHtml ( LayoutFarm htmlContainer, string html, CssActiveSheet cssData ) : void
UpdateScroll ( Point location ) : void

Adjust the scrolling of the panel to the requested location.

myHtmlContainer_NeedUpdateDom ( object sender, EventArgs e ) : void

Method Details

Dispose() protected method

Release the html container resources.
protected Dispose ( bool disposing ) : void
disposing bool
return void

ForceRefreshHtmlDomChange() public method

public ForceRefreshHtmlDomChange ( LayoutFarm doc ) : void
doc LayoutFarm
return void

GetHtml() public method

Get html from the current DOM tree with inline style.
public GetHtml ( ) : string
return string

GetHtmlContainer() public method

public GetHtmlContainer ( ) : HtmlContainer
return HtmlContainer

HtmlPanel() public method

Creates a new HtmlPanel and sets a basic css for it's styling.
public HtmlPanel ( PixelFarm p, int w, int h ) : System
p PixelFarm
w int
h int
return System

IsInputKey() protected method

Used to add arrow keys to the handled keys in OnKeyDown.
protected IsInputKey ( Keys keyData ) : bool
keyData Keys
return bool

LoadHtmlDom() public method

public LoadHtmlDom ( LayoutFarm doc, string defaultCss ) : void
doc LayoutFarm
defaultCss string
return void

OnClick() protected method

Set focus on the control for keyboard scrrollbars handling.
protected OnClick ( EventArgs e ) : void
e EventArgs
return void

OnKeyDown() protected method

Handle key down event for selection, copy and scrollbars handling.
protected OnKeyDown ( KeyEventArgs e ) : void
e KeyEventArgs
return void

OnLayout() protected method

Perform the layout of the html in the control.
protected OnLayout ( LayoutEventArgs levent ) : void
levent LayoutEventArgs
return void

OnMouseDown() protected method

Handle mouse down to handle selection.
protected OnMouseDown ( MouseEventArgs e ) : void
e MouseEventArgs
return void

OnMouseLeave() protected method

Handle mouse leave to handle cursor change.
protected OnMouseLeave ( EventArgs e ) : void
e EventArgs
return void

OnMouseMove() protected method

Handle mouse move to handle hover cursor and text selection.
protected OnMouseMove ( MouseEventArgs e ) : void
e MouseEventArgs
return void

OnMouseUp() protected method

Handle mouse up to handle selection and link click.
protected OnMouseUp ( MouseEventArgs e ) : void
e MouseEventArgs
return void

OnPaint() protected method

Perform paint of the html in the control.
protected OnPaint ( PaintEventArgs e ) : void
e PaintEventArgs
return void

SetHtmlHost() public method

public SetHtmlHost ( HtmlHost htmlhost ) : void
htmlhost HtmlHost
return void