把一个窗体嵌入到WinForm中进行显示,以CMD窗口为例
2016-11-08 14:28
204 查看
1.添加引用
using System.Runtime.InteropServices;
2. 加入以下代码段
using System.Runtime.InteropServices;
2. 加入以下代码段
[DllImport("User32.dll ", EntryPoint = "SetParent")] private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); [DllImport("user32.dll ", EntryPoint = "ShowWindow")] public static extern int ShowWindow(IntPtr hwnd, int nCmdShow); private void btn_ThreadPool_Click(object sender, EventArgs e) { Process p = new Process(); p.StartInfo.FileName = "cmd.exe "; p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;//加上这句效果更好 p.Start(); System.Threading.Thread.Sleep(100);//加上,100 如果效果没有就继续加大 SetParent(p.MainWindowHandle, panel1.Handle); //panel1.Handle为要显示外部程序的容器 ShowWindow(p.MainWindowHandle, 3); }
相关文章推荐
- windows窗体(winform)中嵌入显示Excel工作表。
- 一个winform多个窗体请问怎么弄才不会早任务栏上显示多个,也就是始终只在任务栏上显示一个东西
- android设计实现窗体启动时,显示一个水平进度条,当进行完成后,隐藏该进度条,并显示一张图片
- WinForm:一个登陆窗体引发的问题系列(一):最简单的登陆窗口
- C#中winform窗体如何嵌入cmd命令窗口
- 把一个页面嵌入到另一页面进行弹框显示
- C#在后台注册一个脚本,打开一个子窗口,显示在屏幕中间,关闭子窗体刷新子窗体代码
- C#之WinForm基础 点击button,显示另外一个窗体
- winform开发中,不同窗体根据显示需要进行不同设置,Form属性设置介绍如下。
- winform窗体中嵌入显示Excel文件
- winform判断一个窗口是否打开并显示出来
- 解决VS2005在Winform窗体设计界面中数据源窗口灰化不显示数据源的问题
- 在C#中 从一个picturebox中 按住鼠标左键不放 画一块区域后,另外一个picturebox(在一个winform 窗体上有两个picturebox )上马上把对应的截取图像显示出来
- 一个简单的将GUI程序的log信息输出到关联的Console窗口中(AllocConsole SetConsoleTitle WriteConsole 最后用ShowWindow(GetConsoleWindow)进行显示)
- 原创:windows窗体(winform)中嵌入显示Excel工作表。
- 【开源】做了一个WinForm窗体的投影组件,能够为窗口添加影子效果
- winform如何实现一个窗体显示后,其他的窗体处于不可编辑状态
- winform只显示一个窗体
- WinForm:一个登陆窗体引发的问题系列(五):窗口跳转
- JAVA窗体中嵌入cmd窗口