有关打开唯一窗口不是特别理解 手记
用Form1中的button 4 打开Form 5 这个唯一窗体
Form1中代码
1 #region 打开唯一窗口 2 public List<Form> FormList = new List<Form>(); 3 4 private void button4_Click(object sender, EventArgs e) 5 { 6 Form5 f5 = new Form5(this); 7 8 bool has = false; 9 10 foreach (Form f in FormList) 11 { 12 if (f is Form5) 13 { 14 has = true; 15 } 16 } 17 18 if (has == false) 19 { 20 FormList.Add(f5); 21 f5.Owner = this; 22 f5.Show(); 23 } 24 else 25 { 26 27 } 28 #endregion
Form5中代码
1 #region 打开唯一窗口 2 Form1 F1 = null; 3 4 public Form5(Form1 f1) 5 { 6 InitializeComponent(); 7 F1 = f1; 8 } 9 10 private void Form5_Load(object sender, EventArgs e) 11 { 12 F1.FormList.Remove(this); 13 } 14 #endregion