Export (0) Print
Expand All

WindowsFormsHost Class

An element that allows you to host a Windows Forms control on a WPF page.

Namespace: System.Windows.Forms.Integration
Assembly: WindowsFormsIntegration (in windowsformsintegration.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[ContentPropertyAttribute(L"Child")] 
public ref class WindowsFormsHost : public HwndHost, IKeyboardInputSink
/** @attribute ContentPropertyAttribute("Child") */ 
public class WindowsFormsHost extends HwndHost implements IKeyboardInputSink
ContentPropertyAttribute("Child") 
public class WindowsFormsHost extends HwndHost implements IKeyboardInputSink
<WindowsFormsHost.../>

Use the WindowsFormsHost element to place a Windows Forms control within your WPF element or page.

To host a WPF element in a Windows Forms control or form, use the ElementHost control.

NoteNote:

WindowsFormsIntegration.dll is installed with the Windows Presentation Foundation (WPF) assemblies. The default location for the assembly is %programfiles%\Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll.

To host a Windows Forms control in a WPF element, you must assign the Windows Forms control to the Child property.

Use the PropertyMap property to assign custom mappings between a WindowsFormsHost element and its hosted Windows Forms control. For more information, see Property Mapping.

The following code example demonstrates how to use a WindowsFormsHost element to host a System.Windows.Forms.MaskedTextBox control. For more information, see Walkthrough: Hosting a Windows Forms Control in Windows Presentation Foundation by Using XAML.

<Window x:Class="HostingWfInWpf.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"  
    Title="HostingWfInWpf"
    >

	<Grid>

		<WindowsFormsHost>
			<wf:MaskedTextBox x:Name="mtbDate" Mask="00/00/0000"/>
		</WindowsFormsHost>

	</Grid>

	
</Window>

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"  
    Title="HostingWfInWpf"
    >

  <Grid>

    <WindowsFormsHost>
      <wf:MaskedTextBox x:Name="mtbDate" Mask="00/00/0000"/>
    </WindowsFormsHost>

  </Grid>


</Window>

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Media.Visual
         System.Windows.UIElement
           System.Windows.FrameworkElement
             System.Windows.Interop.HwndHost
              System.Windows.Forms.Integration.WindowsFormsHost

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

Community Additions

ADD
Show:
© 2014 Microsoft