C#的窗体控件调用.exe窗体

来源:互联网 发布:正浩网络是干嘛的 编辑:程序博客网 时间:2024/05/17 04:51

1 在窗体控件中添加命名空间

using System.Diagnostics;
using System.Runtime.InteropServices;

 

2. 在用户控件的构造函数中加载启动路径

Process.Start(@"d:\WindowsFormsApp.exe", this.Handle.ToString());

 

3. 在创建Form窗体时会出现Program.cs类文件,在其Main函数中传入参数string[] args:

        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1(args));
        }

在Application.Run(new Form1()) 中加入闯入的参数args;

 

4. 在创建的Form窗体中加入动态库

        [DllImport("user32.dll")]
        public extern static int SetParent(int child, int parent);

 

5.  传入参数与调用父窗口的函数,如下:

       public Form1(string[] args)
        {

            if (args.Length > 0)
            {
                this.Location = new Point(0, 0);
                SetParent((int)this.Handle, int.Parse(args[0]));
                //MessageBox.Show(args[0]);               
            }    
            InitializeComponent();
        }

 

原创粉丝点击