HtmlElement.CanHaveChildren Property

Definition

Gets a value indicating whether this element can have child elements.

C#
public bool CanHaveChildren { get; }

Property Value

true if element can have child elements; otherwise, false.

Examples

The following code example handles the Click event on HtmlDocument. If an element was not previous selected using a mouse click, the code assigns the element to a private class variable named MoveElement. If an element was selected, the code attempts to append it to the element that was just clicked. This code example requires that your application hosts a WebBrowser control named WebBrowser1, and that you have already added an event handler for the Click event on HtmlDocument.

C#
HtmlDocument doc;
HtmlElement moveElement;

private void EnableElementMove()
{
    if (webBrowser1 != null)
    {
        doc = webBrowser1.Document;
        doc.Click += new HtmlElementEventHandler(doc_Click);
    }
}

void doc_Click(object sender, HtmlElementEventArgs e)
{
    if (moveElement == null)
    {
        moveElement = webBrowser1.Document.GetElementFromPoint(e.ClientMousePosition);
    }
    else
    {
        HtmlElement targetElement = webBrowser1.Document.GetElementFromPoint(e.ClientMousePosition);
        if (targetElement.CanHaveChildren)
        {
            targetElement.AppendChild(moveElement);
            moveElement = null;
        }
    }
}

Remarks

Some elements, such as IMG and SCRIPT, cannot have any children. Use this property before you call AppendChild or InsertAdjacentElement on an arbitrary element.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9