标签:
(效果不是很好,仅供参考)
第一:新建一个类Win32Native,引入win32的外部函数。
代码如下:
public class Win32Native
{
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetParent")]
public extern static IntPtr SetParent(IntPtr childPtr, IntPtr parentPtr);
}
第二:新建两个窗体:
Window1.xaml
Window2.xaml
第三:Window1.xaml.cs中添加引用
using System.Windows.Interop;
第四:在Window1窗体中放上一个Button1
其事件如下:
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实现方法较简单一些,
private void button1_Click(object sender, RoutedEventArgs e)
{
Window2 w2 = new Window2();
w2.MdiParent = this;
w2.Show();
PS:原文地址:http://blog.csdn.net/dotkit/article/details/4799055
标签:
原文地址:http://www.cnblogs.com/dacude/p/4535956.html