The first thing we need to do (after creating a new WPF project) is add few references.
1. Add reference to System.Windows.Forms and WindowsFormsIntegration.
This object is glue layer between WPF and Windows Forms. The WindowsFormsHost is a Framework element, so it can be added to anything in WPF that can take an element. But it has a property Child which takes in a System.Windows.Forms.Control - and this is the control that will be embedded.
Drag and Drop the WindowsFormsHost Control in WPF Window.
Our XAML is going to be extremely simple:
<Window x:Class = "Window1" >
Title="Window1" Height="278" Width="587"
<WindowsFormsHost Name="WindowsFormsHost1" >
3. Add New Windows Forms to the WPF application
Set EnableVisualStyles()of Windows Forms in the New Method.
Public Class Form1
Public Sub New()
' This call is required by the Windows Form Designer.
' Add any initialization after the InitializeComponent() call.
4. After the Form is ready, all we need is adding the form as the child for the WindowsFormsHost control.
In the WPF Window Load event add the following:
Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
Dim Frm As New Form1
Frm.TopLevel = False 'Very important ..
WindowsFormsHost1.Child = Frm
Frm = Nothing
5. See the result
And that is about it for Hosting Windows Forms or Windows Forms Controls inside of WPF Window.