Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/how-to-enable-visual-styles-in-a-hybrid-application.md
T
Andy (Steve) De George be103da07e Replace various WPF include files with content (#1335)
* net-current-v30plus-md.md

* net-current-v40plus-md.md

* tla2sharptla-ui-md.md

* tla2sharptla-uiautomation-md.md

* tla2sharptla-winclient-md.md

* tla2sharptla-xaml-md.md

* tlasharptla-ui-md.md

* tlasharptla-uiautomation-md.md

* tlasharptla-winclient-md.md

* tlasharptla-xaml-md.md

* fix warnings
2022-03-16 12:14:11 -04:00

3.4 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Enable Visual Styles in a Hybrid Application 03/30/2017
csharp
vb
hybrid applications [WPF interoperability]
visual styles [Windows Forms]
95de9b9c-d804-405c-b2d1-49a88c1e0fe1

How to: Enable Visual Styles in a Hybrid Application

This topic shows how to enable visual styles on a Windows Forms control hosted in a WPF-based application.

If your application calls the xref:System.Windows.Forms.Application.EnableVisualStyles%2A method, most of your Windows Forms controls will automatically use visual styles. For more information, see Rendering Controls with Visual Styles.

For a complete code listing of the tasks illustrated in this topic, see Enabling Visual Styles in a Hybrid Application Sample.

Enabling Windows Forms Visual Styles

To enable Windows Forms visual styles

  1. Create a WPF Application project named HostingWfWithVisualStyles.

  2. In Solution Explorer, add references to the following assemblies.

    • WindowsFormsIntegration

    • System.Windows.Forms

  3. In the Toolbox, double-click the xref:System.Windows.Controls.Grid icon to place a xref:System.Windows.Controls.Grid element on the design surface.

  4. In the Properties window, set the values of the xref:System.Windows.FrameworkElement.Height%2A and xref:System.Windows.FrameworkElement.Width%2A properties to Auto.

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

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

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

  8. In MainWindow.xaml.vb or MainWindow.xaml.cs, insert the following code to handle the xref:System.Windows.FrameworkElement.Loaded event.

    [!code-csharpHostingWfWithVisualStyles#11] [!code-vbHostingWfWithVisualStyles#11]

  9. Press F5 to build and run the application.

    The Windows Forms control is painted with visual styles.

Disabling Windows Forms Visual Styles

To disable visual styles, simply remove the call to the xref:System.Windows.Forms.Application.EnableVisualStyles%2A method.

To disable Windows Forms visual styles

  1. Open MainWindow.xaml.vb or MainWindow.xaml.cs in the Code Editor.

  2. Comment out the call to the xref:System.Windows.Forms.Application.EnableVisualStyles%2A method.

  3. Press F5 to build and run the application.

    The Windows Forms control is painted with the default system style.

See also