How to delete an HTML element from a document loaded into the HTMLUI control at run-time?

3 Sep 2020 / 2 minutes to read

The HTML elements loaded in the HTMLUI control are collected in the IHTMLElementsCollection. You can make use of the Remove method of the IHTMLElementsCollection Interface to remove an element from the current collection, and the Refresh method to redraw the HTMLUI control with changes updated in the current document.

The following HTML document contains a textbox and a button element. The following code snippet shows how the textbox and the button are removed from the HTMLUI control’s display at run time.

<!-- HTML document -->




<input type="text" id="txt1"></input>



<input type="button" id="btn1" value="Button1"></input>



IHTMLElement text1;

IHTMLElement btn1;

private System.Windows.Forms.Button button1;

button1.Click += new System.EventHandler(this.button1_Click);

htmluiControl1.LoadFinished += new System.EventHandler(this.htmluiControl1_LoadFinished);

private void htmluiControl1_LoadFinished(object sender, System.EventArgs e)


this.text1 = this.htmluiControl1.Document.GetElementByUserId("txt1");

this.btn1 = this.htmluiControl1.Document.GetElementByUserId("btn1");


private void button1_Click(object sender, System.EventArgs e)





Private text1 As IHTMLElement

Private btn1 As IHTMLElement

Private button1 As System.Windows.Forms.Button

Private button1.Click += New System.EventHandler(Me.button1_Click)

Private htmluiControl1.LoadFinished += New System.EventHandler(Me.htmluiControl1_LoadFinished)

Private Sub htmluiControl1_LoadFinished(ByVal sender As Object, ByVal e As System.EventArgs)

Me.text1 = Me.htmluiControl1.Document.GetElementByUserId("txt1")

Me.btn1 = Me.htmluiControl1.Document.GetElementByUserId("btn1")

End Sub

Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)




End Sub