2 form questions

Mar 1 2008 10:23 AM

Hi guys, I'm new with the C# language and to get the hang of it, I'm trying to build a simple database application consisting of different forms. In my application there is a MenuStrip, and in the MenuStrip there is a ToolStripMenuItem that called Window (the same you have in all the standard Windows applications, if you click on "Window" you see all the forms that are open in your application ... ).

1. What I am trying to achieve is that a event handler starts working after my form is closed (to update my ToolStripMenuItems list). Now it works like this :

f.FormClosed += new FormClosedEventHandler(f_FormClosed);

But this event handler starts BEFORE the form is closed. Is it possible to execute this event handler after the form is closed ?

 

2. I will also give the ToolStripMenuItem a Click eventhandler with it. But this is where it goes wrong ... . I must give a eventhandler name, but that's always a variable (for example, the name of the form). But the compiler doesn't accept it. Here is my code, could somebody tell me how to solve this (see the bold chars) ?

  private void windowsLoaded()
  {
   menuItem.DropDownItems.Clear();
   foreach (Form f in this.MdiChildren)
   {
    ToolStripMenuItem ti = new ToolStripMenuItem();
    ti.Text = f.Name;
    string currentWindowsName = this.ActiveControl.Name;
    if(currentWindowsName == f.Name)
     ti.Checked = true;
    ti.Click += new EventHandler(f.name);
    menuItem.DropDownItems.Add(ti);
   }
   MS.Items.Add(menuItem);
  }