日期:2014-05-17 浏览次数:20872 次
//没有则初始化返回一个编辑框,有则直接返回存在的编辑框 public static Frm_base OpenSomeForm<T>(object[] parameters) where T : Frm_base { Frm_base openForm = null; object obj = parameters.Count() > 0 ? parameters[parameters.Count() - 1] : null; if (!ImspGlobal.listFormID.Contains(obj.ToString())) { openForm=(T)Activator.CreateInstance(typeof(T), parameters); } else { foreach (Form form in Application.OpenForms) { if(form is T) { var data = form as T; if (data.FormCode == obj.ToString()) openForm = data; } } } return openForm; }
//存在直接获取焦点,不存在,添加其编号入集合并打开显示listFormID为Frm_base的附加属性 private void btnShow_Click(object sender, EventArgs e) { var frmEdit = (Frm_Edit)ImspPubFun.OpenSomeForm<Frm_Edit>(new object[] { orderId, null, "06001" + (orderId).ToString() }); if (!ImspGlobal.listFormID.Contains("06001" + (orderId).ToString())) { ImspGlobal.listFormID.Add("06001" + (orderId).ToString()); frmEdit .OnFormClosed += new EventHandler<CloseFormArgs>(frm_OnFormClosed); frmEdit .Show(); } else { frmEdit .Activate(); } }
private void MainForm_Load(object sender, EventArgs e) { listBox1.Items.AddRange(new String[] { "1", "2", "a", "b" }); } private void listBox1_DoubleClick(object sender, EventArgs e) { String strName = listBox1.Text; if (!String.IsNullOrEmpty(strName)) { Boolean bOpen = false; foreach (Form f in Application.OpenForms) { if (f.Name == strName) { bOpen = true; f.BringToFront(); break; } } if (!bOpen) { Form f = new Form(); f.Name = strName; f.Text = strName; f.Show(); } } }
------解决方案--------------------
给个思路:
1、编辑窗体需要增加一个属性DataID,用于标识数据的唯一值;
2、当父窗体需要编辑时,判断打开的编辑窗体有无DataID相同的,若有,将其激活,否则。创建编辑窗体,赋值,包括刷新父窗体的回调;
3、在父窗体中定义回调函数原型,刷新回调函数传回的DataID值那行的数据;
我觉得每个列表界面只需要2个窗体就可以了,一个父窗体,一个编辑窗体。