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.
Unfortunately, activation email could not send to your email. Please try again.

How do I delete an element at run-time from the document loaded in the HTMLUI control?

 

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#

 

 

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

Article ID: Published Date: Last Revised Date: Platform: Control:
805 04/30/2011 07/10/2014 Windows Forms HTMLUIControl
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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.