Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/walkthrough-hosting-a-windows-forms-control-in-wpf.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

3.7 KiB

title, description, titleSuffix, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title description titleSuffix ms.date dev_langs helpviewer_keywords ms.assetid
Host a Windows Forms control in WPF Learn how to host Windows Forms controls in Windows Presentation Foundation, which already provides many controls with a rich feature set. 03/30/2017
csharp
vb
hosting Windows Forms control in WPF [WPF]
9cb88415-39b0-4c46-80c4-ff325b674286

Walkthrough: Hosting a Windows Forms Control in WPF

[!INCLUDETLA2#tla_winclient] provides many controls with a rich feature set. However, you may sometimes want to use Windows Forms controls on your [!INCLUDETLA2#tla_winclient] pages. For example, you may have a substantial investment in existing Windows Forms controls, or you may have a Windows Forms control that provides unique functionality.

This walkthrough shows you how to host a Windows Forms xref:System.Windows.Forms.MaskedTextBox?displayProperty=nameWithType control on a [!INCLUDETLA2#tla_winclient] page by using code.

For a complete code listing of the tasks shown in this walkthrough, see Hosting a Windows Forms Control in WPF Sample.

Prerequisites

You need Visual Studio to complete this walkthrough.

Hosting the Windows Forms Control

To host the MaskedTextBox control

  1. Create a WPF Application project named HostingWfInWpf.

  2. Add references to the following assemblies.

    • WindowsFormsIntegration

    • System.Windows.Forms

  3. Open MainWindow.xaml in the WPF Designer.

  4. Name the xref:System.Windows.Controls.Grid element grid1.

    [!code-xamlHostingWfInWPF#1]

  5. In Design view or XAML view, select the xref:System.Windows.Window element.

  6. In the Properties window, click the Events tab.

  7. Double-click the xref:System.Windows.FrameworkElement.Loaded event.

  8. Insert the following code to handle the xref:System.Windows.FrameworkElement.Loaded event.

    [!code-csharpHostingWfInWPF#10] [!code-vbHostingWfInWPF#10]

  9. At the top of the file, add the following Imports or using statement.

    [!code-csharpHostingWfInWPF#11] [!code-vbHostingWfInWPF#11]

  10. Press F5 to build and run the application.

See also