(The effect is not very good, for reference only)
First: Create a new class win32native, introducing the Win32 external function.
The code is as follows:
public class Win32native
{
[System.Runtime.InteropServices.DllImport ("user32.dll", EntryPoint = "SetParent")]
public extern static IntPtr SetParent (IntPtr childptr, IntPtr parentptr);
}
Second: Create a new two form:
Window1.xaml
Window2.xaml
Third: Add references in Window1.xaml.cs
Using System.Windows.Interop;
IV: Put a Button1 in the Window1 form
The events are as follows:
private void Button1_Click (object sender, RoutedEventArgs e)
{
Window2 W2 = new Window2 ();
W2. Show ();
Windowinterophelper parenthelper = new Windowinterophelper (this);
Windowinterophelper childhelper = new Windowinterophelper (w2);
Win32native.setparent (Childhelper.handle, Parenthelper.handle);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WinForms implementation method is simpler,
private void Button1_Click (object sender, RoutedEventArgs e)
{
Window2 W2 = new Window2 ();
W2. MdiParent = this;
W2. Show ();
PS: Original address: http://blog.csdn.net/dotkit/article/details/4799055
Copy to Google TranslateTranslation Results
Search
Copy
Go WPF methods for implementing MDI Forms