* 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
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 |
|
|
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
-
Create a WPF Application project named
HostingWfWithVisualStyles. -
In Solution Explorer, add references to the following assemblies.
-
WindowsFormsIntegration
-
System.Windows.Forms
-
-
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.
-
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.
-
In Design view or XAML view, select the xref:System.Windows.Window.
-
In the Properties window, click the Events tab.
-
Double-click the xref:System.Windows.FrameworkElement.Loaded event.
-
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]
-
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
-
Open MainWindow.xaml.vb or MainWindow.xaml.cs in the Code Editor.
-
Comment out the call to the xref:System.Windows.Forms.Application.EnableVisualStyles%2A method.
-
Press F5 to build and run the application.
The Windows Forms control is painted with the default system style.