zoukankan      html  css  js  c++  java
  • 把一个窗体嵌入到WinForm中进行显示,以CMD窗口为例

    1.添加引用

    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);
    
            }    
  • 相关阅读:
    前端之JavaScript内容
    前端之CSS内容
    前端之HTML内容
    表单提交中的input、button、submit的区别
    PostgreSQL
    PostgreSQL
    PostgreSQL
    JIRA中的标记语言的语法参考
    Markdown
    Linux
  • 原文地址:https://www.cnblogs.com/arxive/p/6042938.html
Copyright © 2011-2022 走看看