Nasıl yapılır: Karma Uygulamada Görsel Stilleri Etkinleştirme
Bu konuda, WPF tabanlı bir uygulamada barındırılan Windows Forms denetiminde görsel stillerin nasıl etkinleştirildikleri gösterir.
Uygulamanız yöntemini EnableVisualStyles çağırıyorsa, Windows Forms denetimlerinizin çoğu otomatik olarak görsel stilleri kullanır. Daha fazla bilgi için bkz. Görsel Stiller ile Denetimleri İşleme.
Bu konuda gösterilen görevlerin tam kod listesi için bkz. Karma Uygulama Örneğinde Görsel Stilleri Etkinleştirme.
Windows Forms Görsel Stillerini Etkinleştirme
Windows Forms görsel stillerini etkinleştirmek için
adlı bir WPF Uygulaması projesi
HostingWfWithVisualStylesoluşturun.Aşağıdaki Çözüm Gezgini derlemelere başvurular ekleyin.
WindowsFormsIntegration
Sistem. Windows. Forms
Araç Kutusunda simgeye çift Grid tıklar ve tasarım Grid yüzeyine bir öğe yerleştirin.
Aşağıdaki Özellikler penceresi ve özelliklerinin değerlerini Otomatik HeightWidth olarak Height
Tasarım görünümü veya XAML görünümünde öğesini Window seçin.
Özellikler penceresi sekmesine tıklayın.
Olayı çift Loaded tıklatın.
MainWindow.xaml.vb veya MainWindow.xaml.cs içinde, olayı işlemek için aşağıdaki kodu Loaded girin.
private void Window_Loaded(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); }Private Sub Window_Loaded(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 SubUygulamayı derleyip çalıştırmak için F5'e basın.
Windows Forms denetimi görsel stillerle boyanmış.
Windows Forms Görsel Stillerini Devre Dışı Bırakma
Görsel stilleri devre dışı bırakmak için yöntemine yapılan çağrıyı kaldırmanız EnableVisualStyles gerekir.
Forms görsel Windows devre dışı bırakmak için
Kod Düzenleyicisi'nde MainWindow.xaml.vb veya MainWindow.xaml.cs'yi açın.
yöntemine yapılan çağrıyı açıklama olarak EnableVisualStyles açıklamaya alma.
Uygulamayı derleyip çalıştırmak için F5'e basın.
Windows Forms denetimi varsayılan sistem stiliyle boyanmış.