This documentation is archived and is not being maintained.

WindowsFormsHost.Child Property

Gets or sets the child control hosted by the WindowsFormsHost element.

Namespace: System.Windows.Forms.Integration
Assembly: WindowsFormsIntegration (in windowsformsintegration.dll)
XML Namespace:

public Control Child { get; set; }
/** @property */
public Control get_Child ()

/** @property */
public void set_Child (Control value)

public function get Child () : Control

public function set Child (value : Control)

  < object >     < hostedControl  .../>   </ object >  
 object  A WindowsFormsHost element (or a possible subclass).  hostedControl  An element that specifies the hosted Windows Forms control. Specifying the custom control in markup usually requires an xmlns mapping, see XAML Namespaces and Namespace Mapping. 

Property Value

The hosted Windows Forms control.

Exception typeCondition


An attempt was made to assign a top-level form as the hosted control.

Only one child control can be hosted, but Child can have any number of children.

The child control cannot be a top-level form.

If Child is a Form, the form's ControlBox property is set to false.

The following code example demonstrates how to use the Child property to add the hosted control to the WindowsFormsHost element. For more information, see Walkthrough: Hosting an ActiveX Control in Windows Presentation Foundation.

private void WindowLoaded(object sender, RoutedEventArgs e) 
    // Create the interop host control.
    System.Windows.Forms.Integration.WindowsFormsHost host =
        new System.Windows.Forms.Integration.WindowsFormsHost();

    // Create the ActiveX control.
    AxWMPLib.AxWindowsMediaPlayer axWmp = new AxWMPLib.AxWindowsMediaPlayer();

    // Assign the ActiveX control as the host control's child.
    host.Child = axWmp;

    // Add the interop host control to the Grid
    // control's collection of child controls.

    // Play a .wav file with the ActiveX control.
    axWmp.URL = @"C:\WINDOWS\Media\Windows XP Startup.wav";

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0