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);

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

被折叠的 条评论
为什么被折叠?



