Aracılığıyla paylaş


Nasıl yapılır: Karma Uygulamada Görsel Stilleri Etkinleştirme

Bu konu başlığında WPF tabanlı bir uygulamada barındırılan bir Windows Forms denetiminde görsel stillerin nasıl etkinleştirileceği gösterilmektedir.

Uygulamanız yöntemini çağırırsa EnableVisualStyles , Windows Forms denetimlerinizin çoğu otomatik olarak görsel stilleri kullanır. Daha fazla bilgi için bkz . Görsel Stiller ile Denetim İş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ı HostingWfWithVisualStylesbir WPF Uygulaması projesi oluşturun.

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

    • WindowsFormsIntegration

    • System.Windows.Forms

  3. Araç Kutusu'nda simgeye Grid çift tıklayarak tasarım yüzeyine bir Grid öğe yerleştirin.

  4. Özellikler penceresi ve Width özelliklerinin değerlerini Height Otomatik olarak ayarlayın.

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

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

  7. Olaya çift tıklayın Loaded .

  8. MainWindow.xaml.vb veya MainWindow.xaml.cs içinde, olayı işlemek Loaded için aşağıdaki kodu ekleyin.

    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ı derlemek ve çalıştırmak için F5 tuşuna basın.

    Windows Forms denetimi görsel stiller ile 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ı EnableVisualStyles kaldırmanız yeterlidir.

Windows Forms görsel stillerini devre dışı bırakmak için

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

  2. yöntemine yapılan çağrıyı açıklama satırına ekleyin EnableVisualStyles .

  3. Uygulamayı derlemek ve çalıştırmak için F5 tuşuna basın.

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

Ayrıca bkz.