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 ProcessSt