Export (0) Print
Expand All

HtmlElement.CanHaveChildren Property

Note: This property is new in the .NET Framework version 2.0.

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

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public bool CanHaveChildren { get; }
/** @property */
public boolean get_CanHaveChildren ()

public function get CanHaveChildren () : boolean

Property Value

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

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

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.

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;
        }
    }
}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2015 Microsoft