/// <summary>
/// 动态 显示 tab
/// </summary>
/// <param name="sFromName">类名</param>
private void showTab(string sClassName, string MethodName, string sPRODUCTCOMPID)
{
string sFuncName = "showTab";
try
{
bool IsOpened = false;
string sSolutionName = Application.CompanyName;//命名空间
//System.Reflection.Assembly ass = Assembly.Load(sSolutionName);
//System.Windows.Forms.Form form = (System.Windows.Forms.Form)ass.CreateInstance(sSolutionName + "." + sClassName);
// 1.Load(命名空间名称),GetType(命名空间.类名)
Type type = Assembly.Load(sSolutionName).GetType(sSolutionName + "." + sClassName);
// 2.GetMethod(需要调用的方法名称)
MethodInfo method = type.GetMethod(MethodName);
// 3.调用的实例化方法(非静态方法)需要创建类型的一个实例
object obj = Activator.CreateInstance(type);
System.Windows.Forms.Form form = obj as System.Windows.Forms.Form;
//// 4.方法需要传入的参数
//object[] parameters = new object[] { sPRODUCTCOMPID };
//// 5.调用方法,如果调用的是一个静态方法,就不需要第3步(创建类型的实例)
//// 相应地调用静态方法时,Invoke的第一个参数为null
//method.Invoke(obj, parameters);
#region
foreach (SuperTabItem item in superTabControl.Tabs)
{
//已打开
if (item.Name == sClassName)
{
superTabControl.SelectedTab = item;
IsOpened = true;
break;
}
}
if (!IsOpened)
{
if (form != null)
{
form.TopLevel = false;//设置为非*控件 否则会报错
SuperTabItem tab = superTabControl.CreateTab("tabText");// new SuperTabItem();
//TAB.ContainerControl = from;
tab.Name = sClassName;
tab.Text = form.Text;
tab.FixedTabSize = new Size(120, 0);
tab.AttachedControl.Controls.Add(form);
tab.CloseButtonVisible = true;
superTabControl.Tabs.Add(tab);
this.superTabControl.SelectedTab = tab;
form.FormBorderStyle = FormBorderStyle.None;
form.Visible = true;
form.WindowState = FormWindowState.Maximized;
form.Dock = DockStyle.Fill;
form.ShowInTaskbar = false;
form.Show();//必须写在最后,不然显示不了
}
}
#endregion
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}