Category / Section
How to delete an element at run-time from the document loaded in the WinForms HTMLUIControl?
1 min read
Delete an element at runtime
The HTML elements loaded in the HTMLUI control are collected in the IHTMLElementsCollection. The Remove method of the IHTMLElementsCollection Interface removes the element from the current collection and the Refresh method redraws the HTMLUI control with the changes updated in the current document.
The following HTML document contains a textbox and a button element. The code snippet below shows how the textbox and the button are removed from the HTMLUI control's display at run-time.
C#
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) { this.text1.Parent.Children.Remove(this.text1); this.btn1.Parent.Children.Remove(this.btn1); this.htmluiControl1.Refresh(); }
VB
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) Me.text1.Parent.Children.Remove(Me.text1) Me.btn1.Parent.Children.Remove(Me.btn1) Me.htmluiControl1.Refresh() End Sub
Reference link: https://help.syncfusion.com/windowsforms/html-viewer/element-events