Back to Devexpress

CustomDrawEventArgs.DrawHtml(HtmlTemplate, DxHtmlPainterContext, Action<DxHtmlPainterArgs>) Method

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-customdraweventargs-dot-drawhtml-x28-htmltemplate-dxhtmlpaintercontext-action-dxhtmlpainterargs-x29.md

latest4.7 KB
Original Source

CustomDrawEventArgs.DrawHtml(HtmlTemplate, DxHtmlPainterContext, Action<DxHtmlPainterArgs>) Method

Paints the required HTML template inside an element that raised this event. The context parameter allows you to assign an object that transfers mouse events to template elements.

Namespace : DevExpress.XtraGrid.Views.Base

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
public void DrawHtml(
    HtmlTemplate template,
    DxHtmlPainterContext context,
    Action<DxHtmlPainterArgs> setupArgs = null
)
vb
Public Sub DrawHtml(
    template As HtmlTemplate,
    context As DxHtmlPainterContext,
    setupArgs As Action(Of DxHtmlPainterArgs) = Nothing
)

Parameters

NameTypeDescription
templateHtmlTemplate

A template to draw.

| | context | DxHtmlPainterContext |

The object that transfers mouse events from a control to a template instance. This allows you to switch visual states (regular, hovered, pressed, and others) of template elements.

|

Optional Parameters

NameTypeDefaultDescription
setupArgsAction<DxHtmlPainterArgs>null

Sets up required properties of the DxHtmlPainterArgs object.

|

Remarks

The DrawHtml method allows you to paint custom HTML templates inside DevExpress controls. For instance, the code below illustrates how to handle the GridView.CustomDrawCell event to paint a template stored in an HtmlTemplateCollection inside cells that belong to the “Name” column.

csharp
void OnCustomDrawCell(object sender, RowCellCustomDrawEventArgs e) {
    e.DefaultDraw();
    e.Handled = true;
    if (e.Column.FieldName == "Name")
        e.DrawHtml(htmlTemplateCollection1[0]);
}
vb
Private Sub OnCustomDrawCell(ByVal sender As Object, ByVal e As RowCellCustomDrawEventArgs)
    e.DefaultDraw()
    e.Handled = True
    If e.Column.FieldName = "Name" Then e.DrawHtml(htmlTemplateCollection1(0))
End Sub

The optional setupArgs delegate allows you to set up additional settings: specify interactivity keys, modify drawing bounds, assign custom values to elements with ${FieldName} placeholders, and more.

The following example demonstrates how to clip the content based on the container bounds:

csharp
void OnCustomDrawCell(object sender, RowCellCustomDrawEventArgs e) {
    var clipInfo = e.Cache.SaveAndSetClip(e.Bounds);
    try {
        e.DrawHtml(templates[0]);
    } finally {
        e.Cache.ClipInfo.RestoreClipRelease(clipInfo);
    }
}
vb
Private Sub OnCustomDrawCell(ByVal sender As Object, ByVal e As RowCellCustomDrawEventArgs)
    Dim clipInfo = e.Cache.SaveAndSetClip(e.Bounds)
    Try
        e.DrawHtml(templates(0))
    Finally
        e.Cache.ClipInfo.RestoreClipRelease(clipInfo)
    End Try
End Sub

Read the following topic for more information and examples: Custom Draw Templates.

See Also

CustomDrawEventArgs Class

CustomDrawEventArgs Members

DevExpress.XtraGrid.Views.Base Namespace