You can do as follow. In the Main Form you write these lines in InitializeComponent() method:
MainMenu mainMenu1 = new MainMenu();
MenuItem mItem1 = new MenuItem("&Command");
mItem1.MenuItems.Add(new MenuItem("click here",new EventHandler(Commands)));
mainMenu1.MenuItems.Add(mItem1);
this.Menu = mainMenu1;
this.IsMdiContainer = true;
Then make another method as follow:
private void Commands(object sender,System.EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show();
frm2.MdiParent = this;
this.Menu.MenuItems[0].Enabled = false;
}
Till now it is fine. In the Sub form write this method:
private void Form2_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
this.MdiParent.Menu.MenuItems[0].Enabled = true;
}
Hope this will solve your problem... All the best
Gaurav
|