WPF实现MDI窗体的方法
2009-11-11 16:55
330 查看
(效果不是很好,仅供参考)
第一:新建一个类(Class)
Win32Native.cs
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WpfApplication1
{
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();
第一:新建一个类(Class)
Win32Native.cs
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WpfApplication1
{
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();
相关文章推荐
- WPF实现MDI窗体的方法
- [WPF]WPF实现MDI窗体的方法
- 使用WPF实现MDI窗体的方法
- WPF MDI窗体的实现方法
- WPF实现类似MDI子窗体的功能
- C#实现更改MDI窗体背景颜色的方法
- WPF实现MDI窗体
- SL - 整理 - WPF实现MDI窗体
- [小结][N种方法]实现WPF不规则窗体
- 使用Qt实现MDI风格的主窗体
- C#实现在Form里面内嵌dos窗体的方法
- C#中实现鼠标拖动窗体的方法
- delphi把窗体嵌入到dll中。实现方法
- winform 在mdi窗口重绘界面时,mdi挡住主窗体,导致鼠标拖动缩放窗体大小失效的解决方法随笔
- 使用Qt实现MDI风格的主窗体
- WPF如何实现窗体透明——Opacity
- WPF设置启动窗体以及WPF项目中调用winform的方法
- 实现wpf listview listbox 隔行变色的简单方法
- WPF窗体隐藏鼠标光标的方法
- C#最简单的关闭子窗体更新父窗体的实现方法