如何在mdi窗体中运行其他程序 怎样在一个父窗体中把其他程序(如计算器)作为子窗体运行呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 设置这个属性form1.MdiParent=this;//this 为主窗体 Form1 form1 = new Form1(); form1.MdiParent = this; form1.Show(); 当然不是计算器了。用vb我能实现,c#不行么?form1.MdiParent=this;这个对自己写的mdi可以,别的程序不行吧。 “别的程序不行”,楼主是指另外的exe,当然不行;如果是dll,是可以的 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;using System.Diagnostics;using System.Threading;/// <summary> /// /// </summary> /// <param name="hChild"></param> /// <param name="hParent"></param> /// <returns></returns> [DllImport("user32.dll", CharSet = CharSet.Auto)] public extern static IntPtr SetParent(IntPtr hChild, IntPtr hParent); /// <summary> /// /// </summary> /// <param name="lpClassName"></param> /// <param name="lpWindowName"></param> /// <returns></returns> [DllImport("user32.dll", EntryPoint = "FindWindow")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);/// <summary> /// 将计算器和记事本加入到当前的MDI中 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { Process ps = new Process(); ps.StartInfo.FileName = "Notepad.exe"; ps.Start(); for (int i = 0; i < 3; i++) { Thread.Sleep(1000); Application.DoEvents(); } IntPtr Hwnd = FindWindow(null, "无标题 - 记事本"); SetParent(Hwnd, this.Handle); Process ps1 = new Process(); ps1.StartInfo.FileName = "Calc.exe"; ps1.Start(); for (int i = 0; i < 3; i++) { Thread.Sleep(1000); Application.DoEvents(); } IntPtr Hwnd1 = FindWindow(null, "计算器"); SetParent(Hwnd1, this.Handle); } 上面的代码我刚写的测试了,没有问题延迟你自己看着设置,我设置了三秒,也许不需要那么长。。太短的话程序还没有启动,加入MDI会失败 求助,窗口数据传递问题 多个timer并发遇到的问题 两个FORM,如何调用其中一个FORM 中TEXTBOX的内容??(紧急求救~!!!!) 如何获得字体文件名 DataWindow.NET2.0!!!!!!!!!!!!!!! 帮忙推荐一本好书 如何播放资源中的.swf文件 求设计模式的电子文本 如何将数据库中的值显示在web页面上的下拉式菜单中 请教Exception在debug模式下和直接运行时候行为不一致的问题 C#代码实现开机启动是我的界面 OutLook编程问题
Form1 form1 = new Form1();
form1.MdiParent = this;
form1.Show();
form1.MdiParent=this;这个对自己写的mdi可以,别的程序不行吧。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;/// <summary>
///
/// </summary>
/// <param name="hChild"></param>
/// <param name="hParent"></param>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public extern static IntPtr SetParent(IntPtr hChild, IntPtr hParent); /// <summary>
///
/// </summary>
/// <param name="lpClassName"></param>
/// <param name="lpWindowName"></param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
/// <summary>
/// 将计算器和记事本加入到当前的MDI中
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
Process ps = new Process();
ps.StartInfo.FileName = "Notepad.exe";
ps.Start();
for (int i = 0; i < 3; i++)
{
Thread.Sleep(1000);
Application.DoEvents();
}
IntPtr Hwnd = FindWindow(null, "无标题 - 记事本");
SetParent(Hwnd, this.Handle);
Process ps1 = new Process();
ps1.StartInfo.FileName = "Calc.exe";
ps1.Start();
for (int i = 0; i < 3; i++)
{
Thread.Sleep(1000);
Application.DoEvents();
}
IntPtr Hwnd1 = FindWindow(null, "计算器");
SetParent(Hwnd1, this.Handle);
}