exe程序嵌入Winform窗体

本文介绍了如何将exe程序嵌入到Winform窗体中的步骤。首先,创建一个新的Winform程序,添加Panel控件和Button控件,并命名窗体为Mainform。接着,创建一个名为exetowinform的类文件用于引用。在Mainform的CS代码中进行具体操作,实现了exe程序在Winform内的集成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.新建winform程序,添加一个Panel控件和一个button控件,winform窗体命名为:Mainform;


2.新建一个类文件,方便引用,命名为:exetowinform;


3.Mainform中cs代码如下:

  exetowinform fr = null;
        private void button1_Click(object sender, EventArgs e)
        {            
            OpenFileDialog Oppf = new OpenFileDialog();
            Oppf.ShowDialog();
            if (Oppf.FileName != "")
            {
                panel1.Controls.Clear();
                fr = new exetowinform(panel1, "");
                fr.Start(Oppf.FileName);
            }
        }
4.exetowinform类文件代码如下:

 public class exetowinform
    {
        EventHandler appIdleEvent = null;
        Control ParentCon = null;
        string strGUID = "";

        public exetowinform(Control C, string Titlestr)
        {
            appIdleEvent = new EventHandler(Application_Idle);
            ParentCon = C;
            strGUID = Titlestr;
        }

        /// <summary>
        /// 将属性<code>AppFilename</code>指向的应用程序打开并嵌入此容器
        /// </summary>
        public IntPtr Start(string FileNameStr)
        {
            if (m_AppProcess != null)
            {
                Stop();
            }
            try
            {
                ProcessStartInfo info = new ProcessStartInfo(FileNameStr);
           
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值