zoukankan      html  css  js  c++  java
  • WPF实现MDI窗体的方法

    第一:新建一个类(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); 

        testMdiWindow.WindowState = WindowState.Maximized;//加上这句可实现窗口加载时最大化,注意语句位置
    }

     WinForms实现方法较简单一些,

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        Window2 w2 = new Window2();
        w2.MdiParent = this;
        w2.Show();


    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/dotkit/archive/2009/11/11/4799055.aspx

  • 相关阅读:
    第五天
    第四天
    第三天
    四则运算2
    对于搜狗输入法
    用户及用户场景分析
    总结
    第一阶段总结
    第七天
    第六天
  • 原文地址:https://www.cnblogs.com/luluping/p/2335127.html
Copyright © 2011-2022 走看看