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

  1. adlı bir WPF Uygulaması projesi HostingWfWithVisualStyles oluşturun.

  2. Aşağıdaki Çözüm Gezgini derlemelere başvurular ekleyin.

    • WindowsFormsIntegration

    • Sistem. Windows. Forms

  3. Araç Kutusunda simgeye çift Grid tıklar ve tasarım Grid yüzeyine bir öğe yerleştirin.

  4. Aşağıdaki Özellikler penceresi ve özelliklerinin değerlerini Otomatik HeightWidth olarak Height

  5. Tasarım görünümü veya XAML görünümünde öğesini Window seçin.

  6. Özellikler penceresi sekmesine tıklayın.

  7. Olayı çift Loaded tıklatın.

  8. 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 Sub
    
  9. Uygulamayı 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

  1. Kod Düzenleyicisi'nde MainWindow.xaml.vb veya MainWindow.xaml.cs'yi açın.

  2. yöntemine yapılan çağrıyı açıklama olarak EnableVisualStyles açıklamaya alma.

  3. Uygulamayı derleyip çalıştırmak için F5'e basın.

    Windows Forms denetimi varsayılan sistem stiliyle boyanmış.

Ayrıca bkz.