업데이트: 2007년 11월
이 항목에서는 WPF 기반 응용 프로그램에 호스팅되는 Windows Forms 컨트롤에서 Microsoft Windows XP 비주얼 스타일을 사용하는 방법을 보여 줍니다.
응용 프로그램에서 EnableVisualStyles 메서드를 호출하면 대부분의 Windows Forms 컨트롤에서는 응용 프로그램이 Microsoft Windows XP에서 실행될 경우 자동으로 비주얼 스타일을 사용합니다. 자세한 내용은 비주얼 스타일을 사용하여 컨트롤 렌더링을 참조하십시오.
이 항목에서 설명하는 작업의 전체 코드 목록은 혼합 응용 프로그램에서 비주얼 스타일 사용 샘플을 참조하십시오.
참고
표시되는 대화 상자와 메뉴 명령은 실제 설정이나 버전에 따라 도움말에서 설명하는 것과 다를 수 있습니다. 설정을 변경하려면 도구 메뉴에서 설정 가져오기 및 내보내기를 선택합니다.
Windows Forms 비주얼 스타일 사용
Windows Forms 비주얼 스타일을 사용하려면
HostingWfWithVisualStyles라는 WPF 응용 프로그램 프로젝트를 만듭니다.
솔루션 탐색기에서 WindowsFormsIntegration.dll이라는 WindowsFormsIntegration 어셈블리에 대한 참조를 추가합니다.
이 파일의 기본 위치는 %programfiles%\Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll입니다.
솔루션 탐색기에서 System.Windows.Forms.dll이라는 Windows Forms 어셈블리에 대한 참조를 추가합니다.
코드 편집기에서 Window1.xaml을 엽니다.
다음 코드를 삽입하여 Loaded 이벤트에 대한 이벤트 처리기를 연결합니다.
<Window x:Class="Window1" xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml" Title="HostingWfWithVisualStyles" Height="300" Width="300" Loaded="WindowLoaded" >
<Window x:Class="HostingWfWithVisualStyles.Window1" xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml" Title="HostingWfWithVisualStyles" Height="300" Width="300" Loaded="WindowLoaded" >
코드 편집기에서 Window1.xaml.cs를 엽니다.
다음 코드를 삽입하여 Loaded 이벤트를 처리합니다.
Private Sub WindowLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs) ' Comment out the following line to disable visual ' styles for the hosted Windows Forms control. System.Windows.Forms.Application.EnableVisualStyles() ' Create a WindowsFormsHost element to host ' the Windows Forms control. Dim host As New System.Windows.Forms.Integration.WindowsFormsHost() ' Create a Windows Forms tab control. Dim tc As New System.Windows.Forms.TabControl() tc.TabPages.Add("Tab1") tc.TabPages.Add("Tab2") ' Assign the Windows Forms tab control as the hosted control. host.Child = tc ' Assign the host element to the parent Grid element. Me.grid1.Children.Add(host) End Sub
private void WindowLoaded(object sender, RoutedEventArgs e) { // Comment out the following line to disable visual // styles for the hosted Windows Forms control. System.Windows.Forms.Application.EnableVisualStyles(); // Create a WindowsFormsHost element to host // the Windows Forms control. System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost(); // Create a Windows Forms tab control. System.Windows.Forms.TabControl tc = new System.Windows.Forms.TabControl(); tc.TabPages.Add("Tab1"); tc.TabPages.Add("Tab2"); // Assign the Windows Forms tab control as the hosted control. host.Child = tc; // Assign the host element to the parent Grid element. this.grid1.Children.Add(host); }
F5 키를 눌러 응용 프로그램을 빌드 및 실행합니다.
Windows Forms 컨트롤이 비주얼 스타일로 그려집니다.
Windows Forms 비주얼 스타일 사용 안 함
비주얼 스타일을 사용하지 않으려면 EnableVisualStyles 메서드에 대한 호출을 제거하기만 하면 됩니다.
Windows Forms 비주얼 스타일을 사용하지 않으려면
코드 편집기에서 Window1.xaml.cs를 엽니다.
EnableVisualStyles 메서드에 대한 호출을 주석으로 처리합니다.
F5 키를 눌러 응용 프로그램을 빌드 및 실행합니다.
Windows Forms 컨트롤이 기본 시스템 스타일로 그려집니다.
참고 항목
작업
연습: Windows Presentation Foundation에서 Windows Forms 컨트롤 호스팅
개념
참조
System.Windows.Forms.VisualStyles