Articles in this section
Category / Section

How to change the characteristic of an element before it is being displayed using the prerender document event of the WinForms HTMLUIControl?

1 min read

PrerendererDocument event

The Characteristic of an element can be easily changed in the PrerenderDocument Event of the HTMLUI control.

The Prerenderdocument event is raised when the elements in the HTML document are created in the HTMLUI control but their size and location are not calculated yet.

This event is used to change the characteristics of the element before they are positioned in the HTMLUI control.

The following snippet shows how an image reference is changed for a page in the HTMLUI at run time in the PrerenderDocument Event.


Hashtable htmlelements = new Hashtable();
this.htmluiControl1.PreRenderDocument += new Syncfusion.Windows.Forms.HTMLUI.PreRenderDocumentEventHandler(this.htmluiControl1_PreRenderDocument);
private void htmluiControl1_PreRenderDocument(object sender,PreRenderDocumentArgs e)
    this.htmlelements = e.Document.GetElementsByNameHash();
    ArrayList imgs = this.htmlelements["img"] as ArrayList;
    foreach(BaseElement elem in imgs)
        string oldValue = elem.Attributes["src"].Value;
        string newValue = e.Document.CurrentDirectory + "\\sync.jpg";
        elem.Attributes["src"].Value = oldValue.Replace(elem.Attributes["src"].Value, newValue);



Private htmlelements As Hashtable = New Hashtable()
Private Me.htmluiControl1.PreRenderDocument += New Syncfusion.Windows.Forms.HTMLUI.PreRenderDocumentEventHandler(Me.htmluiControl1 _PreRenderDocument)
Private Sub htmluiControl1_PreRenderDocument(ByVal sender As Object, ByVal e As PreRenderDocumentArgs)
    Me.htmlelements = e.Document.GetElementsByNameHash()
    Dim imgs As ArrayList = CType(IIf(TypeOf Me.htmlelements("img") Is ArrayList,  Me.htmlelements("img"), Nothing), ArrayList)
    For Each elem As BaseElement In imgs
        Dim oldValue As String = elem.Attributes("src").Value
        Dim newValue As String = e.Document.CurrentDirectory & "\sync.jpg"
        elem.Attributes("src").Value = oldValue.Replace(elem.Attributes("src").Value, newValue)
    Next elem
End Sub


Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment