WinFormTools/WinformGeneralDeveloperFrame/ChildWinManagement.cs

124 lines
4.1 KiB
C#
Raw Normal View History

using System;
2021-04-13 17:46:18 +08:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
2021-05-15 13:57:34 +08:00
using DevExpress.Utils;
using MES.Form;
2021-04-13 17:46:18 +08:00
using WinformGeneralDeveloperFrame.Commons;
namespace WinformGeneralDeveloperFrame
{
public sealed class ChildWinManagement
{
private ChildWinManagement()
{
}
2021-04-25 18:49:28 +08:00
public static bool ExistWin(System.Windows.Forms.Form MDIwin, string caption)
2021-04-13 17:46:18 +08:00
{
bool flag = false;
2021-04-25 18:49:28 +08:00
foreach (System.Windows.Forms.Form mdiChild in MDIwin.MdiChildren)
2021-04-13 17:46:18 +08:00
{
if (mdiChild.Text == caption)
{
flag = true;
mdiChild.Show();
mdiChild.Activate();
break;
}
}
return flag;
}
2021-05-15 13:57:34 +08:00
public static System.Windows.Forms.Form LoadMdiForm(System.Windows.Forms.Form mainDialog, Type formType,string code)
2021-04-13 17:46:18 +08:00
{
bool flag = false;
2021-04-25 18:49:28 +08:00
System.Windows.Forms.Form form = (System.Windows.Forms.Form)null;
foreach (System.Windows.Forms.Form mdiChild in mainDialog.MdiChildren)
2021-04-13 17:46:18 +08:00
{
if (mdiChild.GetType() == formType)
{
flag = true;
form = mdiChild;
break;
}
}
if (!flag)
{
2021-05-15 13:57:34 +08:00
2021-04-25 18:49:28 +08:00
form = (System.Windows.Forms.Form)Activator.CreateInstance(formType);
var dd = form.GetType().GetBaseType().GetField("Menucode");
2021-05-15 13:57:34 +08:00
dd.SetValue(form, code);
2021-04-13 17:46:18 +08:00
form.MdiParent = mainDialog;
form.Show();
}
2021-05-15 13:57:34 +08:00
2021-04-13 17:46:18 +08:00
form.BringToFront();
form.Activate();
return form;
}
2021-04-25 18:49:28 +08:00
public static System.Windows.Forms.Form LoadShowForm(System.Windows.Forms.Form mainDialog, Type formType, string caption, int formId)
2021-04-13 17:46:18 +08:00
{
bool flag = false;
2021-04-25 18:49:28 +08:00
System.Windows.Forms.Form form = (System.Windows.Forms.Form)null;
foreach (System.Windows.Forms.Form mdiChild in mainDialog.MdiChildren)
2021-04-13 17:46:18 +08:00
{
if (mdiChild.GetType() == formType)
{
flag = true;
form = mdiChild;
break;
}
}
if (!flag)
{
2021-04-25 18:49:28 +08:00
form = (System.Windows.Forms.Form)Activator.CreateInstance(formType);
2021-04-13 17:46:18 +08:00
form.MdiParent = mainDialog;
}
2021-04-25 18:49:28 +08:00
FrmShowForm frmShowForm = form as FrmShowForm;
2021-04-13 17:46:18 +08:00
frmShowForm.Text = caption;
2021-04-17 15:40:26 +08:00
frmShowForm.formId = formId;
frmShowForm.Init();
frmShowForm.Show();
2021-04-25 18:49:28 +08:00
MainForm manForm = mainDialog as MainForm;
2021-04-13 17:46:18 +08:00
frmShowForm.mainform = manForm;
form.BringToFront();
form.Activate();
return form;
}
public static void PopControlForm(Type control, string caption)
{
object instance = ReflectionUtil.CreateInstance(control);
if (!typeof(Control).IsAssignableFrom(instance.GetType()))
return;
2021-04-25 18:49:28 +08:00
System.Windows.Forms.Form form = new System.Windows.Forms.Form();
2021-04-13 17:46:18 +08:00
form.WindowState = FormWindowState.Maximized;
form.ShowIcon = false;
form.Text = caption;
form.ShowInTaskbar = false;
form.StartPosition = FormStartPosition.CenterScreen;
Control control1 = instance as Control;
control1.Dock = DockStyle.Fill;
form.Controls.Add(control1);
2021-04-25 18:49:28 +08:00
int num = (int)form.ShowDialog();
2021-04-13 17:46:18 +08:00
}
public static void PopDialogForm(Type type)
{
object instance = ReflectionUtil.CreateInstance(type);
2021-04-25 18:49:28 +08:00
if (!typeof(System.Windows.Forms.Form).IsAssignableFrom(instance.GetType()))
2021-04-13 17:46:18 +08:00
return;
2021-04-25 18:49:28 +08:00
System.Windows.Forms.Form form = instance as System.Windows.Forms.Form;
2021-04-13 17:46:18 +08:00
form.ShowInTaskbar = false;
form.StartPosition = FormStartPosition.CenterScreen;
2021-04-25 18:49:28 +08:00
int num = (int)form.ShowDialog();
2021-04-13 17:46:18 +08:00
}
}
}