)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to delete an element at run-time from the document loaded in the WinForms HTMLUIControl?

Platform: WinForms |
Control: HTMLUIControl |
Published Date: April 30, 2011 |
Last Revised Date: January 3, 2020

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon