form1.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace p272_18 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void newToolStripMenuItem_Click(object sender, EventArgs e) { Form2 newMDIChild = new Form2(); newMDIChild.MdiParent = this; newMDIChild.Show(); num++; //MessageBox.Show(sender.ToString());//显示的是new.. //this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); if (num >= 1) { this.editToolStripMenuItem1.Visible = true; } } public static int num = 0; private void Form1_MdiChildActivate(object sender, EventArgs e) { if (num == 0) { this.editToolStripMenuItem1.Visible = false; } } } }
form2.csusing System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace p272_18 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_FormClosed(object sender, FormClosedEventArgs e) { Form1.num--; } } }