using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using CoreFS.CA06;
namespace Core.Mes.Client.Comm.Control
{
///
/// Form处理类
///
public class FormHelper
{
///
/// 打开其他工程中的窗体
///
/// 主窗体 (this.MdiParent)
/// 一般为窗体的全称 + 配置信息(可无)
/// 程序集名
/// 窗体的全称
/// 窗体的中文名
public static void OpenOtherAssemblyForm(Form vParentFrm, string vKey, string vAssemblyName,
string vClassName, string vCaption)
{
//检查窗体是否已经打开
foreach (Form mdiChild in vParentFrm.MdiChildren)
{
if ((mdiChild as FrmBase).Key == vKey)
{
mdiChild.Activate();
return;
}
}
//实例化窗体并打开
try
{
Assembly baseFormAssembly = Assembly.Load(vAssemblyName);
Type type = baseFormAssembly.GetType(vClassName);
System.Diagnostics.Debug.Assert(type.IsSubclassOf(typeof(FrmBase)));
FrmBase form = Activator.CreateInstance(type, true) as FrmBase;
form.MdiParent = vParentFrm;
form.Text = vCaption;
form.Key = vKey;
form.Show();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}