Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
HtmlElement Class
 CanHaveChildren Property
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
.NET Framework Class Library
HtmlElement..::.CanHaveChildren Property

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

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic
Public ReadOnly Property CanHaveChildren As Boolean
C#
public bool CanHaveChildren { get; }
Visual C++
public:
property bool CanHaveChildren {
    bool get ();
}
F#
member CanHaveChildren : bool

Property Value

Type: System..::.Boolean
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.

Visual Basic
Dim WithEvents Doc As HtmlDocument
Dim MoveElement As HtmlElement

Private Sub EnableElementMove()
    If (WebBrowser1 IsNot Nothing) Then
        Doc = WebBrowser1.Document
    End If
End Sub

Private Sub Document_Click(ByVal sender As Object, ByVal args As HtmlElementEventArgs) Handles Doc.Click
    If (MoveElement Is Nothing) Then
        MoveElement = WebBrowser1.Document.GetElementFromPoint(args.ClientMousePosition)
    Else
        With WebBrowser1.Document
            Dim TargetElement As HtmlElement = .GetElementFromPoint(args.ClientMousePosition)
            If (TargetElement.CanHaveChildren) Then

                TargetElement.AppendChild(MoveElement)
                MoveElement = Nothing
            End If
        End With
    End If
End Sub
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;
                }
            }
        }

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker