Bagikan melalui


WindowsFormsHost.Child Properti

Definisi

Mendapatkan atau mengatur kontrol anak yang dihosting WindowsFormsHost oleh elemen .

public:
 property System::Windows::Forms::Control ^ Child { System::Windows::Forms::Control ^ get(); void set(System::Windows::Forms::Control ^ value); };
public System.Windows.Forms.Control Child { get; set; }
member this.Child : System.Windows.Forms.Control with get, set
Public Property Child As Control

Nilai Properti

Kontrol Windows Forms yang dihosting.

Pengecualian

Upaya dilakukan untuk menetapkan formulir tingkat atas sebagai kontrol yang dihosting.

Contoh

Contoh kode berikut menunjukkan cara menggunakan Child properti untuk menambahkan kontrol yang dihosting ke WindowsFormsHost elemen . Untuk informasi selengkapnya, lihat Panduan: Menghosting Kontrol ActiveX di WPF.

private void Window_Loaded(object sender, RoutedEventArgs e) 
{
    // Create the interop host control.
    System.Windows.Forms.Integration.WindowsFormsHost host =
        new System.Windows.Forms.Integration.WindowsFormsHost();

    // Create the ActiveX control.
    var axWmp = new WmpAxLib.AxWindowsMediaPlayer();

    // Assign the ActiveX control as the host control's child.
    host.Child = axWmp;

    // Add the interop host control to the Grid
    // control's collection of child controls.
    this.grid1.Children.Add(host);

    // Play a .wav file with the ActiveX control.
    axWmp.URL = @"C:\Windows\Media\tada.wav";
}
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)

    ' Create the interop host control.
    Dim host As New System.Windows.Forms.Integration.WindowsFormsHost()

    ' Create the ActiveX control.
    Dim axWmp As New AxWMPLib.AxWindowsMediaPlayer()

    ' Assign the ActiveX control as the host control's child.
    host.Child = axWmp

    ' Add the interop host control to the Grid
    ' control's collection of child controls.
    Me.grid1.Children.Add(host)

    ' Play a .wav file with the ActiveX control.
    axWmp.URL = "C:\Windows\Media\tada.wav"

End Sub

Keterangan

Hanya satu kontrol anak yang dapat dihosting, tetapi Child dapat memiliki sejumlah anak.

Kontrol anak tidak boleh berupa formulir tingkat atas.

Jika Child adalah Form, properti formulir ControlBox diatur ke false.

Penggunaan Teks XAML

< benda>

< hostedControl.../>

</ benda>

Nilai XAML

Objek Elemen WindowsFormsHost (atau kemungkinan subkelas).

hostedControl Elemen yang menentukan kontrol Windows Forms yang dihosting. Menentukan kontrol kustom dalam markup biasanya memerlukan pemetaan xmlns, lihat XAML Namespaces dan Namespace Mapping untuk WPF XAML.

Berlaku untuk

Lihat juga